Changes in / [c13e8dc8:9c35431]
- Files:
-
- 75 added
- 73 deleted
- 88 edited
-
doc/proposals/concurrency/text/basics.tex (modified) (10 diffs)
-
doc/proposals/concurrency/text/cforall.tex (modified) (3 diffs)
-
doc/proposals/concurrency/text/concurrency.tex (modified) (28 diffs)
-
doc/proposals/concurrency/text/frontpgs.tex (modified) (2 diffs)
-
doc/proposals/concurrency/text/future.tex (modified) (3 diffs)
-
doc/proposals/concurrency/text/internals.tex (modified) (14 diffs)
-
doc/proposals/concurrency/text/parallelism.tex (modified) (2 diffs)
-
doc/proposals/concurrency/text/results.tex (modified) (8 diffs)
-
doc/proposals/concurrency/text/together.tex (modified) (1 diff)
-
doc/proposals/concurrency/version (modified) (1 diff)
-
src/CodeGen/CodeGenerator.cc (modified) (1 diff)
-
src/CodeGen/CodeGenerator.h (modified) (1 diff)
-
src/CodeGen/FixNames.cc (modified) (5 diffs)
-
src/CodeGen/FixNames.h (modified) (2 diffs)
-
src/Common/PassVisitor.h (modified) (3 diffs)
-
src/Common/PassVisitor.impl.h (modified) (5 diffs)
-
src/Common/PassVisitor.proto.h (modified) (1 diff)
-
src/Concurrency/Keywords.cc (modified) (13 diffs)
-
src/Concurrency/Waitfor.cc (modified) (18 diffs)
-
src/ControlStruct/ExceptTranslate.cc (modified) (29 diffs)
-
src/ControlStruct/ForExprMutator.cc (modified) (1 diff)
-
src/ControlStruct/LabelFixer.cc (modified) (3 diffs)
-
src/ControlStruct/LabelFixer.h (modified) (3 diffs)
-
src/ControlStruct/MLEMutator.cc (modified) (3 diffs)
-
src/ControlStruct/Mutate.cc (modified) (2 diffs)
-
src/GenPoly/Box.cc (modified) (14 diffs)
-
src/GenPoly/InstantiateGeneric.cc (modified) (4 diffs)
-
src/GenPoly/Specialize.cc (modified) (3 diffs)
-
src/InitTweak/FixGlobalInit.cc (modified) (6 diffs)
-
src/InitTweak/FixInit.cc (modified) (6 diffs)
-
src/InitTweak/InitTweak.cc (modified) (12 diffs)
-
src/MakeLibCfa.cc (modified) (2 diffs)
-
src/Makefile.in (modified) (5 diffs)
-
src/Parser/DeclarationNode.cc (modified) (1 diff)
-
src/Parser/ParseNode.h (modified) (5 diffs)
-
src/Parser/StatementNode.cc (modified) (16 diffs)
-
src/Parser/parser.yy (modified) (11 diffs)
-
src/ResolvExpr/AlternativeFinder.cc (modified) (12 diffs)
-
src/ResolvExpr/AlternativeFinder.h (modified) (4 diffs)
-
src/ResolvExpr/Resolver.cc (modified) (6 diffs)
-
src/ResolvExpr/typeops.h (modified) (1 diff)
-
src/SymTab/AddVisit.h (modified) (2 diffs)
-
src/SymTab/Autogen.cc (modified) (6 diffs)
-
src/SymTab/Autogen.h (modified) (2 diffs)
-
src/SymTab/ImplementationType.cc (added)
-
src/SymTab/ImplementationType.h (added)
-
src/SymTab/Indexer.cc (modified) (15 diffs)
-
src/SymTab/Indexer.h (modified) (4 diffs)
-
src/SymTab/TypeEquality.cc (added)
-
src/SymTab/TypeEquality.h (added)
-
src/SymTab/Validate.cc (modified) (3 diffs)
-
src/SymTab/module.mk (modified) (1 diff)
-
src/SynTree/CompoundStmt.cc (modified) (1 diff)
-
src/SynTree/DeclStmt.cc (modified) (1 diff)
-
src/SynTree/Mutator.cc (modified) (1 diff)
-
src/SynTree/Mutator.h (modified) (1 diff)
-
src/SynTree/ReferenceToType.cc (modified) (2 diffs)
-
src/SynTree/Statement.cc (modified) (19 diffs)
-
src/SynTree/Statement.h (modified) (19 diffs)
-
src/SynTree/SynTree.h (modified) (1 diff)
-
src/SynTree/TupleExpr.cc (modified) (2 diffs)
-
src/SynTree/Type.h (modified) (3 diffs)
-
src/SynTree/Visitor.cc (modified) (1 diff)
-
src/SynTree/Visitor.h (modified) (1 diff)
-
src/Tuples/TupleAssignment.cc (modified) (16 diffs)
-
src/Tuples/TupleExpansion.cc (modified) (3 diffs)
-
src/driver/cfa.cc (modified) (1 diff)
-
src/libcfa/Makefile.am (modified) (2 diffs)
-
src/libcfa/Makefile.in (modified) (16 diffs)
-
src/libcfa/assert.c (modified) (3 diffs)
-
src/libcfa/bits/align.h (deleted)
-
src/libcfa/bits/containers.h (modified) (1 diff)
-
src/libcfa/bits/debug.c (deleted)
-
src/libcfa/bits/debug.h (deleted)
-
src/libcfa/bits/defs.h (modified) (1 diff)
-
src/libcfa/bits/locks.h (modified) (5 diffs)
-
src/libcfa/concurrency/alarm.c (modified) (5 diffs)
-
src/libcfa/concurrency/coroutine.c (modified) (4 diffs)
-
src/libcfa/concurrency/invoke.c (modified) (4 diffs)
-
src/libcfa/concurrency/kernel.c (modified) (27 diffs)
-
src/libcfa/concurrency/kernel_private.h (modified) (3 diffs)
-
src/libcfa/concurrency/monitor.c (modified) (37 diffs)
-
src/libcfa/concurrency/preemption.c (modified) (16 diffs)
-
src/libcfa/concurrency/thread.c (modified) (3 diffs)
-
src/libcfa/exception.c (modified) (22 diffs)
-
src/libcfa/exception.h (modified) (2 diffs)
-
src/libcfa/interpose.c (modified) (3 diffs)
-
src/libcfa/libhdr.h (added)
-
src/libcfa/libhdr/libalign.h (added)
-
src/libcfa/libhdr/libdebug.c (added)
-
src/libcfa/libhdr/libdebug.h (added)
-
src/libcfa/libhdr/libtools.h (added)
-
src/libcfa/stdhdr/assert.h (modified) (1 diff)
-
src/prelude/builtins.c (modified) (2 diffs)
-
src/tests/.expect/32/KRfunctions.txt (added)
-
src/tests/.expect/32/attributes.txt (added)
-
src/tests/.expect/32/declarationSpecifier.txt (added)
-
src/tests/.expect/32/extension.txt (added)
-
src/tests/.expect/32/functions.txt (added)
-
src/tests/.expect/32/gccExtensions.txt (added)
-
src/tests/.expect/32/literals.txt (added)
-
src/tests/.expect/32/math1.txt (added)
-
src/tests/.expect/32/math2.txt (added)
-
src/tests/.expect/32/math3.txt (added)
-
src/tests/.expect/64/KRfunctions.txt (added)
-
src/tests/.expect/64/attributes.txt (added)
-
src/tests/.expect/64/declarationSpecifier.txt (added)
-
src/tests/.expect/64/extension.txt (added)
-
src/tests/.expect/64/functions.txt (added)
-
src/tests/.expect/64/gccExtensions.txt (added)
-
src/tests/.expect/64/gmp.txt (added)
-
src/tests/.expect/64/literals.txt (added)
-
src/tests/.expect/64/math1.txt (added)
-
src/tests/.expect/64/math2.txt (added)
-
src/tests/.expect/64/math3.txt (added)
-
src/tests/.expect/KRfunctions.x64.txt (deleted)
-
src/tests/.expect/KRfunctions.x86.txt (deleted)
-
src/tests/.expect/attributes.x64.txt (deleted)
-
src/tests/.expect/attributes.x86.txt (deleted)
-
src/tests/.expect/concurrent/boundedBuffer.txt (added)
-
src/tests/.expect/concurrent/coroutine.txt (added)
-
src/tests/.expect/concurrent/datingService.txt (added)
-
src/tests/.expect/concurrent/fmtLines.txt (added)
-
src/tests/.expect/concurrent/matrixSum.txt (added)
-
src/tests/.expect/concurrent/monitor.txt (added)
-
src/tests/.expect/concurrent/multi-monitor.txt (added)
-
src/tests/.expect/concurrent/pingpong.txt (added)
-
src/tests/.expect/concurrent/preempt.txt (added)
-
src/tests/.expect/concurrent/prodcons.txt (added)
-
src/tests/.expect/concurrent/sched-ext-barge.txt (added)
-
src/tests/.expect/concurrent/sched-ext-dtor.txt (added)
-
src/tests/.expect/concurrent/sched-ext-else.txt (added)
-
src/tests/.expect/concurrent/sched-ext-recurse.txt (added)
-
src/tests/.expect/concurrent/sched-ext-statment.txt (added)
-
src/tests/.expect/concurrent/sched-ext-when.txt (added)
-
src/tests/.expect/concurrent/sched-int-block.txt (added)
-
src/tests/.expect/concurrent/sched-int-disjoint.txt (added)
-
src/tests/.expect/concurrent/sched-int-wait.txt (added)
-
src/tests/.expect/concurrent/thread.txt (added)
-
src/tests/.expect/declarationErrors.txt (modified) (2 diffs)
-
src/tests/.expect/declarationSpecifier.x64.txt (deleted)
-
src/tests/.expect/declarationSpecifier.x86.txt (deleted)
-
src/tests/.expect/extension.x64.txt (deleted)
-
src/tests/.expect/extension.x86.txt (deleted)
-
src/tests/.expect/functions.x64.txt (deleted)
-
src/tests/.expect/functions.x86.txt (deleted)
-
src/tests/.expect/gccExtensions.x64.txt (deleted)
-
src/tests/.expect/gccExtensions.x86.txt (deleted)
-
src/tests/.expect/gmp.x64.txt (deleted)
-
src/tests/.expect/literals.x64.txt (deleted)
-
src/tests/.expect/literals.x86.txt (deleted)
-
src/tests/.expect/math1.x64.txt (deleted)
-
src/tests/.expect/math1.x86.txt (deleted)
-
src/tests/.expect/math2.x64.txt (deleted)
-
src/tests/.expect/math2.x86.txt (deleted)
-
src/tests/.expect/math3.x64.txt (deleted)
-
src/tests/.expect/math3.x86.txt (deleted)
-
src/tests/.expect/with-statement.txt (deleted)
-
src/tests/.in/fmtLines.txt (added)
-
src/tests/Makefile.am (modified) (4 diffs)
-
src/tests/Makefile.in (modified) (4 diffs)
-
src/tests/boundedBuffer.c (added)
-
src/tests/concurrent/.expect/monitor.txt (deleted)
-
src/tests/concurrent/.expect/multi-monitor.txt (deleted)
-
src/tests/concurrent/.expect/preempt.txt (deleted)
-
src/tests/concurrent/.expect/thread.txt (deleted)
-
src/tests/concurrent/examples/.expect/boundedBuffer.txt (deleted)
-
src/tests/concurrent/examples/.expect/datingService.txt (deleted)
-
src/tests/concurrent/examples/.expect/matrixSum.txt (deleted)
-
src/tests/concurrent/examples/boundedBuffer.c (deleted)
-
src/tests/concurrent/examples/datingService.c (deleted)
-
src/tests/concurrent/examples/matrixSum.c (deleted)
-
src/tests/concurrent/monitor.c (deleted)
-
src/tests/concurrent/multi-monitor.c (deleted)
-
src/tests/concurrent/preempt.c (deleted)
-
src/tests/concurrent/signal/.expect/block.txt (deleted)
-
src/tests/concurrent/signal/.expect/disjoint.txt (deleted)
-
src/tests/concurrent/signal/.expect/wait.txt (deleted)
-
src/tests/concurrent/signal/barge.c (deleted)
-
src/tests/concurrent/signal/block.c (deleted)
-
src/tests/concurrent/signal/disjoint.c (deleted)
-
src/tests/concurrent/signal/wait.c (deleted)
-
src/tests/concurrent/thread.c (deleted)
-
src/tests/concurrent/waitfor/.expect/barge.txt (deleted)
-
src/tests/concurrent/waitfor/.expect/dtor.txt (deleted)
-
src/tests/concurrent/waitfor/.expect/else.txt (deleted)
-
src/tests/concurrent/waitfor/.expect/recurse.txt (deleted)
-
src/tests/concurrent/waitfor/.expect/statment.txt (deleted)
-
src/tests/concurrent/waitfor/.expect/when.txt (deleted)
-
src/tests/concurrent/waitfor/barge.c (deleted)
-
src/tests/concurrent/waitfor/dtor.c (deleted)
-
src/tests/concurrent/waitfor/else.c (deleted)
-
src/tests/concurrent/waitfor/parse.c (deleted)
-
src/tests/concurrent/waitfor/parse2.c (deleted)
-
src/tests/concurrent/waitfor/recurse.c (deleted)
-
src/tests/concurrent/waitfor/simple.c (deleted)
-
src/tests/concurrent/waitfor/statment.c (deleted)
-
src/tests/concurrent/waitfor/when.c (deleted)
-
src/tests/coroutine.c (added)
-
src/tests/coroutine/.expect/coroutine.txt (deleted)
-
src/tests/coroutine/.expect/fmtLines.txt (deleted)
-
src/tests/coroutine/.expect/pingpong.txt (deleted)
-
src/tests/coroutine/.expect/prodcons.txt (deleted)
-
src/tests/coroutine/.in/fmtLines.txt (deleted)
-
src/tests/coroutine/coroutine.c (deleted)
-
src/tests/coroutine/fmtLines.c (deleted)
-
src/tests/coroutine/pingpong.c (deleted)
-
src/tests/coroutine/prodcons.c (deleted)
-
src/tests/datingService.c (added)
-
src/tests/except-mac.h (modified) (4 diffs)
-
src/tests/fmtLines.c (added)
-
src/tests/matrixSum.c (added)
-
src/tests/monitor.c (added)
-
src/tests/multi-monitor.c (added)
-
src/tests/pingpong.c (added)
-
src/tests/preempt.c (added)
-
src/tests/prodcons.c (added)
-
src/tests/pybin/settings.py (deleted)
-
src/tests/pybin/test_run.py (deleted)
-
src/tests/pybin/tools.py (modified) (4 diffs)
-
src/tests/sched-ext-barge.c (added)
-
src/tests/sched-ext-dtor.c (added)
-
src/tests/sched-ext-else.c (added)
-
src/tests/sched-ext-parse.c (added)
-
src/tests/sched-ext-recurse.c (added)
-
src/tests/sched-ext-statment.c (added)
-
src/tests/sched-ext-when.c (added)
-
src/tests/sched-ext.c (added)
-
src/tests/sched-int-barge.c (added)
-
src/tests/sched-int-block.c (added)
-
src/tests/sched-int-disjoint.c (added)
-
src/tests/sched-int-wait.c (added)
-
src/tests/test.py (modified) (11 diffs)
-
src/tests/thread.c (added)
-
src/tests/waitfor.c (added)
-
src/tests/with-statement.c (deleted)
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/concurrency/text/basics.tex
rc13e8dc8 r9c35431 4 4 % ====================================================================== 5 5 % ====================================================================== 6 Before any detailed discussion of the concurrency and parallelism in \CFA, it is important to describe the basics of concurrency and how they are expressed in \CFA user code.6 Before any detailed discussion of the concurrency and parallelism in \CFA, it is important to describe the basics of concurrency and how they are expressed in \CFA user-code. 7 7 8 8 \section{Basics of concurrency} … … 11 11 Execution with a single thread and multiple stacks where the thread is self-scheduling deterministically across the stacks is called coroutining. Execution with a single and multiple stacks but where the thread is scheduled by an oracle (non-deterministic from the thread perspective) across the stacks is called concurrency. 12 12 13 Therefore, a minimal concurrency system can be achieved by creating coroutines, which instead of context -switching among each other, always ask an oracle where to context-switch next. While coroutines can execute on the caller?s stack-frame, stack-full coroutines allow full generality and are sufficient as the basis for concurrency. The aforementioned oracle is a scheduler and the whole system now follows a cooperative threading-model (aka non-preemptive scheduling). The oracle/scheduler can either be a stack-less or stack-full entity and correspondingly require one or two context-switches to run a different coroutine. In any case, a subset of concurrency related challenges start to appear. For the complete set of concurrency challenges to occur, the only feature missing is preemption.14 15 A scheduler introduces order of execution uncertainty, while preemption introduces uncertainty about where context switches occur. Mutualexclusion and synchronization are ways of limiting non-determinism in a concurrent system. Now it is important to understand that uncertainty is desirable; uncertainty can be used by runtime systems to significantly increase performance and is often the basis of giving a user the illusion that tasks are running in parallel. Optimal performance in concurrent applications is often obtained by having as much non-determinism as correctness allows.16 17 \section{\protect\CFA 's Thread Building Blocks}18 One of the important features that are missing in C is threading. On modern architectures, a lack of threading is unacceptable~\cite{Sutter05, Sutter05b}, and therefore modern programming languages must have the proper tools to allow users to write efficient concurrent programs to take advantage of parallelism. As an extension of C, \CFA needs to express these concepts in a way that is as natural as possible to programmers familiar with imperative languages. And being a system-level language means programmers expect to choose precisely which features they need and which cost they are willing to pay.19 20 \section{Coroutines: A Stepping Stone}\label{coroutine}21 While the main focus of this proposal is concurrency and parallelism, it is important to address coroutines, which are actually a significant building block of a concurrency system. Coroutines need to deal with context switches and other context-management operations. Therefore, this proposal includes coroutines both as an intermediate step for the implementation of threads, and a first-class feature of \CFA. Furthermore, many design challenges of threads are at least partially present in designing coroutines, which makes the design effort that much more relevant. The core \acrshort{api} of coroutines revolves around two features: independent call-stacks and \code{suspend}/\code{resume}.13 Therefore, a minimal concurrency system can be achieved by creating coroutines, which instead of context switching among each other, always ask an oracle where to context switch next. While coroutines can execute on the caller's stack-frame, stack-full coroutines allow full generality and are sufficient as the basis for concurrency. The aforementioned oracle is a scheduler and the whole system now follows a cooperative threading-model (a.k.a non-preemptive scheduling). The oracle/scheduler can either be a stack-less or stack-full entity and correspondingly require one or two context switches to run a different coroutine. In any case, a subset of concurrency related challenges start to appear. For the complete set of concurrency challenges to occur, the only feature missing is preemption. 14 15 A scheduler introduces order of execution uncertainty, while preemption introduces uncertainty about where context-switches occur. Mutual-exclusion and synchronization are ways of limiting non-determinism in a concurrent system. Now it is important to understand that uncertainty is desirable; uncertainty can be used by runtime systems to significantly increase performance and is often the basis of giving a user the illusion that tasks are running in parallel. Optimal performance in concurrent applications is often obtained by having as much non-determinism as correctness allows. 16 17 \section{\protect\CFA 's Thread Building Blocks} 18 One of the important features that is missing in C is threading. On modern architectures, a lack of threading is unacceptable~\cite{Sutter05, Sutter05b}, and therefore modern programming languages must have the proper tools to allow users to write performant concurrent programs to take advantage of parallelism. As an extension of C, \CFA needs to express these concepts in a way that is as natural as possible to programmers familiar with imperative languages. And being a system-level language means programmers expect to choose precisely which features they need and which cost they are willing to pay. 19 20 \section{Coroutines: A stepping stone}\label{coroutine} 21 While the main focus of this proposal is concurrency and parallelism, it is important to address coroutines, which are actually a significant building block of a concurrency system. Coroutines need to deal with context-switches and other context-management operations. Therefore, this proposal includes coroutines both as an intermediate step for the implementation of threads, and a first class feature of \CFA. Furthermore, many design challenges of threads are at least partially present in designing coroutines, which makes the design effort that much more relevant. The core \acrshort{api} of coroutines revolve around two features: independent call stacks and \code{suspend}/\code{resume}. 22 22 23 23 \begin{table} … … 133 133 \end{table} 134 134 135 A good example of a problem made easier with coroutines is generators, like the Fibonacci sequence. This problem comes with the challenge of decoupling how a sequence is generated and how it is used. Table \ref{lst:fibonacci-c} shows conventional approaches to writing generators in C. All three of these approach suffer from strong coupling. The left and cent reapproaches require that the generator have knowledge of how the sequence is used, while the rightmost approach requires holding internal state between calls on behalf of the generator and makes it much harder to handle corner cases like the Fibonacci seed.135 A good example of a problem made easier with coroutines is generators, like the Fibonacci sequence. This problem comes with the challenge of decoupling how a sequence is generated and how it is used. Table \ref{lst:fibonacci-c} shows conventional approaches to writing generators in C. All three of these approach suffer from strong coupling. The left and center approaches require that the generator have knowledge of how the sequence is used, while the rightmost approach requires holding internal state between calls on behalf of the generator and makes it much harder to handle corner cases like the Fibonacci seed. 136 136 137 137 Listing \ref{lst:fibonacci-cfa} is an example of a solution to the Fibonacci problem using \CFA coroutines, where the coroutine stack holds sufficient state for the next generation. This solution has the advantage of having very strong decoupling between how the sequence is generated and how it is used. Indeed, this version is as easy to use as the \code{fibonacci_state} solution, while the implementation is very similar to the \code{fibonacci_func} example. … … 233 233 One important design challenge for implementing coroutines and threads (shown in section \ref{threads}) is that the runtime system needs to run code after the user-constructor runs to connect the fully constructed object into the system. In the case of coroutines, this challenge is simpler since there is no non-determinism from preemption or scheduling. However, the underlying challenge remains the same for coroutines and threads. 234 234 235 The runtime system needs to create the coroutine ?s stack and more importantly prepare it for the first resumption. The timing of the creation is non-trivial since users both expect to have fully constructed objects once execution enters the coroutine main and to be able to resume the coroutine from the constructor. There are several solutions to this problem but the chosen optioneffectively forces the design of the coroutine.236 237 Furthermore, \CFA faces an extra challenge as polymorphic routines create invisible thunks when cast to non-polymorphic routines and these thunks have function scope. For example, the following code, while looking benign, can run into undefined behaviour because of thunks:235 The runtime system needs to create the coroutine's stack and more importantly prepare it for the first resumption. The timing of the creation is non-trivial since users both expect to have fully constructed objects once execution enters the coroutine main and to be able to resume the coroutine from the constructor. There are several solutions to this problem but the chosen options effectively forces the design of the coroutine. 236 237 Furthermore, \CFA faces an extra challenge as polymorphic routines create invisible thunks when casted to non-polymorphic routines and these thunks have function scope. For example, the following code, while looking benign, can run into undefined behaviour because of thunks: 238 238 239 239 \begin{cfacode} … … 268 268 } 269 269 \end{ccode} 270 The problem in this example is a storage management issue, the function pointer \code{_thunk0} is only valid until the end of the block, which limits the viable solutions because storing the function pointer for too long causes Undefined Behavio ur; i.e., the stack-based thunk being destroyed before it can be used. This challenge is an extension of challenges that come with second-class routines. Indeed, GCC nested routines also have the limitation that nested routine cannot be passed outside of the declaration scope. The case of coroutines and threads is simply an extension of this problem to multiple callstacks.270 The problem in this example is a storage management issue, the function pointer \code{_thunk0} is only valid until the end of the block, which limits the viable solutions because storing the function pointer for too long causes Undefined Behavior; i.e., the stack-based thunk being destroyed before it can be used. This challenge is an extension of challenges that come with second-class routines. Indeed, GCC nested routines also have the limitation that nested routine cannot be passed outside of the declaration scope. The case of coroutines and threads is simply an extension of this problem to multiple call-stacks. 271 271 272 272 \subsection{Alternative: Composition} … … 310 310 symmetric_coroutine<>::yield_type 311 311 \end{cfacode} 312 Often, the canonical threading paradigm in languages is based on function pointers, pthread being one of the most well -known examples. The main problem of this approach is that the thread usage is limited to a generic handle that must otherwise be wrapped in a custom type. Since the custom type is simple to write in \CFA and solves several issues, added support for routine/lambda based coroutines adds very little.312 Often, the canonical threading paradigm in languages is based on function pointers, pthread being one of the most well known examples. The main problem of this approach is that the thread usage is limited to a generic handle that must otherwise be wrapped in a custom type. Since the custom type is simple to write in \CFA and solves several issues, added support for routine/lambda based coroutines adds very little. 313 313 314 314 A variation of this would be to use a simple function pointer in the same way pthread does for threads : … … 327 327 This semantics is more common for thread interfaces but coroutines work equally well. As discussed in section \ref{threads}, this approach is superseded by static approaches in terms of expressivity. 328 328 329 \subsection{Alternative: Trait- Based Coroutines}330 331 Finally ,the underlying approach, which is the one closest to \CFA idioms, is to use trait-based lazy coroutines. This approach defines a coroutine as anything that satisfies the trait \code{is_coroutine} and is used as a coroutine.329 \subsection{Alternative: Trait-based coroutines} 330 331 Finally the underlying approach, which is the one closest to \CFA idioms, is to use trait-based lazy coroutines. This approach defines a coroutine as anything that satisfies the trait \code{is_coroutine} and is used as a coroutine. 332 332 333 333 \begin{cfacode} … … 369 369 370 370 \section{Thread Interface}\label{threads} 371 The basic building blocks of multi threading in \CFA are \glspl{cfathread}. Both user and kernel threads are supported, where user threads are the concurrency mechanism and kernel threads are the parallel mechanism. User threads offer a flexible and lightweight interface. A thread can be declared using a struct declaration \code{thread} as follows:371 The basic building blocks of multi-threading in \CFA are \glspl{cfathread}. Both user and kernel threads are supported, where user threads are the concurrency mechanism and kernel threads are the parallel mechanism. User threads offer a flexible and lightweight interface. A thread can be declared using a struct declaration \code{thread} as follows: 372 372 373 373 \begin{cfacode} … … 394 394 \end{cfacode} 395 395 396 In this example, threads of type \code{foo} start execution in the \code{void main(foo &)} routine, which prints \code{"Hello World!" .} While this thesis encourages this approach to enforce stronglytyped programming, users may prefer to use the routine-based thread semantics for the sake of simplicity. With the static semantics it is trivial to write a thread type that takes a function pointer as a parameter and executes it on its stack asynchronously.396 In this example, threads of type \code{foo} start execution in the \code{void main(foo &)} routine, which prints \code{"Hello World!"}. While this thesis encourages this approach to enforce strongly-typed programming, users may prefer to use the routine-based thread semantics for the sake of simplicity. With the static semantics it is trivial to write a thread type that takes a function pointer as a parameter and executes it on its stack asynchronously. 397 397 \begin{cfacode} 398 398 typedef void (*voidFunc)(int); … … 419 419 int main() { 420 420 FuncRunner f = {hello, 42}; 421 return 0 ?422 } 423 \end{cfacode} 424 425 A consequence of the strongly typed approach to main is that memory layout of parameters and return values to/from a thread are now explicitly specified in the \acrshort{api}.421 return 0' 422 } 423 \end{cfacode} 424 425 A consequence of the strongly-typed approach to main is that memory layout of parameters and return values to/from a thread are now explicitly specified in the \acrshort{api}. 426 426 427 427 Of course for threads to be useful, it must be possible to start and stop threads and wait for them to complete execution. While using an \acrshort{api} such as \code{fork} and \code{join} is relatively common in the literature, such an interface is unnecessary. Indeed, the simplest approach is to use \acrshort{raii} principles and have threads \code{fork} after the constructor has completed and \code{join} before the destructor runs. -
doc/proposals/concurrency/text/cforall.tex
rc13e8dc8 r9c35431 7 7 The following is a quick introduction to the \CFA language, specifically tailored to the features needed to support concurrency. 8 8 9 \CFA is an extension of ISO-C and therefore supports all of the same paradigms as C. It is a non-object-oriented system-language, meaning most of the major abstractions have either no runtime overhead or can be opt ed out easily. Like C, the basics of \CFA revolve around structures and routines, which are thin abstractions over machine code. The vast majority of the code produced by the \CFA translator respects memory layouts and callingconventions laid out by C. Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (e.g., {\tt this}), it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent10 values''~\cite[3.15]{C11}}, most importantly construction and destruction of objects. Most of the following code examples can be found on the \CFA website~\cite{www-cfa} .9 \CFA is an extension of ISO-C and therefore supports all of the same paradigms as C. It is a non-object-oriented system-language, meaning most of the major abstractions have either no runtime overhead or can be opt-out easily. Like C, the basics of \CFA revolve around structures and routines, which are thin abstractions over machine code. The vast majority of the code produced by the \CFA translator respects memory-layouts and calling-conventions laid out by C. Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (e.g., {\tt this}), it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent 10 values''~\cite[3.15]{C11}}, most importantly construction and destruction of objects. Most of the following code examples can be found on the \CFA website~\cite{www-cfa} 11 11 12 12 % ====================================================================== … … 72 72 % ====================================================================== 73 73 \section{Constructors/Destructors} 74 Object life time is often a challenge in concurrency. \CFA uses the approach of giving concurrent meaning to object lifetime as a means of synchronization and/or mutual exclusion. Since \CFA relies heavily on the lifetime of objects, constructors and destructors isa core feature required for concurrency and parallelism. \CFA uses the following syntax for constructors and destructors :74 Object life-time is often a challenge in concurrency. \CFA uses the approach of giving concurrent meaning to object life-time as a mean of synchronization and/or mutual exclusion. Since \CFA relies heavily on the life time of objects, constructors and destructors are a core feature required for concurrency and parallelism. \CFA uses the following syntax for constructors and destructors : 75 75 \begin{cfacode} 76 76 struct S { … … 135 135 \end{cfacode} 136 136 137 Note that the type use for assertions can be either an \code{otype} or a \code{dtype}. Types declare d as \code{otype} refer to ``complete'' objects, i.e., objects with a size, a default constructor, a copy constructor, a destructor and an assignment operator. Using \code{dtype,} on the other hand,has none of these assumptions but is extremely restrictive, it only guarantees the object is addressable.137 Note that the type use for assertions can be either an \code{otype} or a \code{dtype}. Types declares as \code{otype} refer to ``complete'' objects, i.e., objects with a size, a default constructor, a copy constructor, a destructor and an assignment operator. Using \code{dtype} on the other hand has none of these assumptions but is extremely restrictive, it only guarantees the object is addressable. 138 138 139 139 % ====================================================================== -
doc/proposals/concurrency/text/concurrency.tex
rc13e8dc8 r9c35431 4 4 % ====================================================================== 5 5 % ====================================================================== 6 Several tool s can be used to solve concurrency challenges. Since many of these challenges appear with the use of mutable shared-state, some languages and libraries simply disallow mutable shared-state (Erlang~\cite{Erlang}, Haskell~\cite{Haskell}, Akka (Scala)~\cite{Akka}). In these paradigms, interaction among concurrent objects relies on message passing~\cite{Thoth,Harmony,V-Kernel} or other paradigms closely relate to networking concepts (channels~\cite{CSP,Go} for example). However, in languages that use routine calls as their core abstraction mechanism, these approaches force a clear distinction between concurrent and non-concurrent paradigms (i.e., message passing versus routine calls). This distinction in turn means that, in order to be effective, programmers need to learn two sets of designpatterns. While this distinction can be hidden away in library code, effective use of the library still has to take both paradigms into account.6 Several tool can be used to solve concurrency challenges. Since many of these challenges appear with the use of mutable shared-state, some languages and libraries simply disallow mutable shared-state (Erlang~\cite{Erlang}, Haskell~\cite{Haskell}, Akka (Scala)~\cite{Akka}). In these paradigms, interaction among concurrent objects relies on message passing~\cite{Thoth,Harmony,V-Kernel} or other paradigms closely relate to networking concepts (channels~\cite{CSP,Go} for example). However, in languages that use routine calls as their core abstraction-mechanism, these approaches force a clear distinction between concurrent and non-concurrent paradigms (i.e., message passing versus routine call). This distinction in turn means that, in order to be effective, programmers need to learn two sets of designs patterns. While this distinction can be hidden away in library code, effective use of the library still has to take both paradigms into account. 7 7 8 8 Approaches based on shared memory are more closely related to non-concurrent paradigms since they often rely on basic constructs like routine calls and shared objects. At the lowest level, concurrent paradigms are implemented as atomic operations and locks. Many such mechanisms have been proposed, including semaphores~\cite{Dijkstra68b} and path expressions~\cite{Campbell74}. However, for productivity reasons it is desirable to have a higher-level construct be the core concurrency paradigm~\cite{HPP:Study}. 9 9 10 An approach that is worth mentioning because it is gaining in popularity is transactional memory~\cite{Herlihy93}. While this approach is even pursued by system languages like \CC~\cite{Cpp-Transactions}, the performance and feature set is currently too restrictive to be the main concurrency paradigm for system languages, which is why it was rejected as the core paradigm for concurrency in \CFA.11 12 One of the most natural, elegant, and efficient mechanisms for synchronization and communication, especially for shared-memory systems, is the \emph{monitor}. Monitors were first proposed by Brinch Hansen~\cite{Hansen73} and later described and extended by C.A.R.~Hoare~\cite{Hoare74}. Many programming languages---e.g., Concurrent Pascal~\cite{ConcurrentPascal}, Mesa~\cite{Mesa}, Modula~\cite{Modula-2}, Turing~\cite{Turing:old}, Modula-3~\cite{Modula-3}, NeWS~\cite{NeWS}, Emerald~\cite{Emerald}, \uC~\cite{Buhr92a} and Java~\cite{Java}---provide monitors as explicit language constructs. In addition, operating-system kernels and device drivers have a monitor-like structure, although they often use lower-level primitives such as semaphores or locks to simulate monitors. For these reasons, this project proposes monitors as the core concurrency construct.10 An approach that is worth mentioning because it is gaining in popularity is transactional memory~\cite{Herlihy93}. While this approach is even pursued by system languages like \CC~\cite{Cpp-Transactions}, the performance and feature set is currently too restrictive to be the main concurrency paradigm for systems language, which is why it was rejected as the core paradigm for concurrency in \CFA. 11 12 One of the most natural, elegant, and efficient mechanisms for synchronization and communication, especially for shared-memory systems, is the \emph{monitor}. Monitors were first proposed by Brinch Hansen~\cite{Hansen73} and later described and extended by C.A.R.~Hoare~\cite{Hoare74}. Many programming languages---e.g., Concurrent Pascal~\cite{ConcurrentPascal}, Mesa~\cite{Mesa}, Modula~\cite{Modula-2}, Turing~\cite{Turing:old}, Modula-3~\cite{Modula-3}, NeWS~\cite{NeWS}, Emerald~\cite{Emerald}, \uC~\cite{Buhr92a} and Java~\cite{Java}---provide monitors as explicit language constructs. In addition, operating-system kernels and device drivers have a monitor-like structure, although they often use lower-level primitives such as semaphores or locks to simulate monitors. For these reasons, this project proposes monitors as the core concurrency-construct. 13 13 14 14 \section{Basics} … … 19 19 20 20 \subsection{Synchronization} 21 As for mutual-exclusion, low-level synchronization primitives often offer good performance and good flexibility at the cost of ease of use. Again, higher-level mechanism soften simplify usage by adding better coupling between synchronization and data, e.g.: message passing, or offering a simpler solution to otherwise involved challenges. As mentioned above, synchronization can be expressed as guaranteeing that event \textit{X} always happens before \textit{Y}. Most of the time, synchronization happens within a critical section, where threads must acquire mutual-exclusion in a certain order. However, it may also be desirable to guarantee that event \textit{Z} does not occur between \textit{X} and \textit{Y}. Not satisfying this property is called barging. For example, where event \textit{X} tries to effect event \textit{Y} but another thread acquires the critical section and emits \textit{Z} before \textit{Y}. The classic example is the thread that finishes using a resource and unblocks a thread waiting to use the resource, but the unblocked thread must compete again to acquire the resource. Preventing or detecting barging is an involved challenge with low-level locks, which can be made much easier by higher-level constructs. This challenge is often split into two different methods, barging avoidance and barging prevention. Algorithms that use flag variables to detect barging threads are said to be using barging avoidance, while algorithms that baton-pass locks~\cite{Andrews89} between threads instead of releasing the locks are said to be using barging prevention.21 As for mutual-exclusion, low-level synchronization primitives often offer good performance and good flexibility at the cost of ease of use. Again, higher-level mechanism often simplify usage by adding better coupling between synchronization and data, e.g.: message passing, or offering a simpler solution to otherwise involved challenges. As mentioned above, synchronization can be expressed as guaranteeing that event \textit{X} always happens before \textit{Y}. Most of the time, synchronization happens within a critical section, where threads must acquire mutual-exclusion in a certain order. However, it may also be desirable to guarantee that event \textit{Z} does not occur between \textit{X} and \textit{Y}. Not satisfying this property is called barging. For example, where event \textit{X} tries to effect event \textit{Y} but another thread acquires the critical section and emits \textit{Z} before \textit{Y}. The classic example is the thread that finishes using a resource and unblocks a thread waiting to use the resource, but the unblocked thread must compete again to acquire the resource. Preventing or detecting barging is an involved challenge with low-level locks, which can be made much easier by higher-level constructs. This challenge is often split into two different methods, barging avoidance and barging prevention. Algorithms that use flag variables to detect barging threads are said to be using barging avoidance, while algorithms that baton-pass locks~\cite{Andrews89} between threads instead of releasing the locks are said to be using barging prevention. 22 22 23 23 % ====================================================================== … … 26 26 % ====================================================================== 27 27 % ====================================================================== 28 A monitor is a set of routines that ensure mutual exclusion when accessing shared state. This concept is generally associated with Object-Oriented Languages like Java~\cite{Java} or \uC~\cite{uC++book} but does not strictly require OO semantics. The only requirement is the ability to declare a handle to a shared object and a set of routines that act on it :28 A monitor is a set of routines that ensure mutual exclusion when accessing shared state. This concept is generally associated with Object-Oriented Languages like Java~\cite{Java} or \uC~\cite{uC++book} but does not strictly require OO semantics. The only requirements is the ability to declare a handle to a shared object and a set of routines that act on it : 29 29 \begin{cfacode} 30 30 typedef /*some monitor type*/ monitor; … … 39 39 % ====================================================================== 40 40 % ====================================================================== 41 \subsection{Call Semantics} \label{call}41 \subsection{Call semantics} \label{call} 42 42 % ====================================================================== 43 43 % ====================================================================== … … 103 103 int f5(graph(monitor*) & mutex m); 104 104 \end{cfacode} 105 The problem is to identify which object(s) should be acquired. Furthermore, each object needs to be acquired only once. In the case of simple routines like \code{f1} and \code{f2} it is easy to identify an exhaustive list of objects to acquire on entry. Adding indirections (\code{f3}) still allows the compiler and programmer to identify which object is acquired. However, adding in arrays (\code{f4}) makes it much harder. Array lengths are not necessarily known in C, and even then, making sure objects are only acquired once becomes none-trivial. This problem can be extended to absurd limits like \code{f5}, which uses a graph of monitors. To make the issue tractable, this project imposes the requirement that a routine may only acquire one monitor per parameter and it must be the type of the parameter with at most one level of indirection (ignoring potential qualifiers). Also note that while routine \code{f3} can be supported, meaning that monitor \code{**m} is acquired, passing an array to this routine would be type-safe and yet result in undefined behaviour because only the first element of the array is acquired. However, this ambiguity is part of the C type-system with respects to arrays. For this reason, \code{mutex} is disallowed in the context where arrays may be passed:105 The problem is to identify which object(s) should be acquired. Furthermore, each object needs to be acquired only once. In the case of simple routines like \code{f1} and \code{f2} it is easy to identify an exhaustive list of objects to acquire on entry. Adding indirections (\code{f3}) still allows the compiler and programmer to identify which object is acquired. However, adding in arrays (\code{f4}) makes it much harder. Array lengths are not necessarily known in C, and even then, making sure objects are only acquired once becomes none-trivial. This problem can be extended to absurd limits like \code{f5}, which uses a graph of monitors. To make the issue tractable, this project imposes the requirement that a routine may only acquire one monitor per parameter and it must be the type of the parameter with at most one level of indirection (ignoring potential qualifiers). Also note that while routine \code{f3} can be supported, meaning that monitor \code{**m} is be acquired, passing an array to this routine would be type safe and yet result in undefined behaviour because only the first element of the array is acquired. However, this ambiguity is part of the C type-system with respects to arrays. For this reason, \code{mutex} is disallowed in the context where arrays may be passed: 106 106 \begin{cfacode} 107 107 int f1(monitor& mutex m); //Okay : recommended case … … 137 137 The \gls{multi-acq} monitor lock allows a monitor lock to be acquired by both \code{bar} or \code{baz} and acquired again in \code{foo}. In the calls to \code{bar} and \code{baz} the monitors are acquired in opposite order. 138 138 139 However, such use leads to the lock acquiring order problem s. In the example above, the user uses implicit ordering in the case of function \code{foo} but explicit ordering in the case of \code{bar} and \code{baz}. This subtle difference means that calling these routines concurrently may lead to deadlock and is therefore Undefined Behaviour. As shown~\cite{Lister77}, solving this problem requires:139 However, such use leads to the lock acquiring order problem. In the example above, the user uses implicit ordering in the case of function \code{foo} but explicit ordering in the case of \code{bar} and \code{baz}. This subtle difference means that calling these routines concurrently may lead to deadlock and is therefore Undefined Behavior. As shown~\cite{Lister77}, solving this problem requires: 140 140 \begin{enumerate} 141 141 \item Dynamically tracking of the monitor-call order. … … 155 155 } 156 156 \end{cfacode} 157 This example shows a trivial solution to the bank-account transfer problem~\cite{BankTransfer}. Without \gls{multi-acq} and \gls{bulk-acq}, the solution to this problem is much more involved and requires careful engineering.157 This example shows a trivial solution to the bank-account transfer-problem~\cite{BankTransfer}. Without \gls{multi-acq} and \gls{bulk-acq}, the solution to this problem is much more involved and requires careful engineering. 158 158 159 159 \subsection{\code{mutex} statement} \label{mutex-stmt} 160 160 161 The call semantics discussed above have one software engineering issue, only a named routine can acquire the mutual-exclusion of a set of monitor. \CFA offers the \code{mutex} statement to work around the need for unnecessary names, avoiding a major software engineering problem~\cite{2FTwoHardThings}. Table \ref{lst:mutex-stmt} shows an example of the \code{mutex} statement, which introduces a new scope in which the mutual-exclusion of a set of monitor is acquired. Beyond naming, the \code{mutex} statement has no semantic difference from a routine call with \code{mutex} parameters.161 The call semantics discussed above have one software engineering issue, only a named routine can acquire the mutual-exclusion of a set of monitor. \CFA offers the \code{mutex} statement to workaround the need for unnecessary names, avoiding a major software engineering problem~\cite{2FTwoHardThings}. Table \ref{lst:mutex-stmt} shows an example of the \code{mutex} statement, which introduces a new scope in which the mutual-exclusion of a set of monitor is acquired. Beyond naming, the \code{mutex} statement has no semantic difference from a routine call with \code{mutex} parameters. 162 162 163 163 \begin{table} … … 196 196 % ====================================================================== 197 197 % ====================================================================== 198 Once the call semantics are established, the next step is to establish data semantics. Indeed, until now a monitor is used simply as a generic handle but in most cases monitors contain shared data. This data should be intrinsic to the monitor declaration to prevent any accidental use of data without its appropriate protection. For example, here is a complete version of the counter show nin section \ref{call}:198 Once the call semantics are established, the next step is to establish data semantics. Indeed, until now a monitor is used simply as a generic handle but in most cases monitors contain shared data. This data should be intrinsic to the monitor declaration to prevent any accidental use of data without its appropriate protection. For example, here is a complete version of the counter showed in section \ref{call}: 199 199 \begin{cfacode} 200 200 monitor counter_t { … … 227 227 % ====================================================================== 228 228 % ====================================================================== 229 \section{Internal Scheduling} \label{intsched}229 \section{Internal scheduling} \label{intsched} 230 230 % ====================================================================== 231 231 % ====================================================================== 232 232 In addition to mutual exclusion, the monitors at the core of \CFA's concurrency can also be used to achieve synchronization. With monitors, this capability is generally achieved with internal or external scheduling as in~\cite{Hoare74}. Since internal scheduling within a single monitor is mostly a solved problem, this thesis concentrates on extending internal scheduling to multiple monitors. Indeed, like the \gls{bulk-acq} semantics, internal scheduling extends to multiple monitors in a way that is natural to the user but requires additional complexity on the implementation side. 233 233 234 First, here is a simple example of internal scheduling :234 First, here is a simple example of internal-scheduling : 235 235 236 236 \begin{cfacode} … … 253 253 } 254 254 \end{cfacode} 255 There are two details to note here. First, the \code{signal} is a delayed operation, it only unblocks the waiting thread when it reaches the end of the critical section. This semantic is needed to respect mutual-exclusion, i.e., the signaller and signalled thread cannot be in the monitor simultaneously. The alternative is to return immediately after the call to \code{signal}, which is significantly more restrictive. Second, in \CFA, while it is common to store a \code{condition} as a field of the monitor, a \code{condition} variable can be stored/created independently of a monitor. Here routine \code{foo} waits for the \code{signal} from \code{bar} before making further progress, e nsuring a basic ordering.256 257 An important aspect of the implementation is that \CFA does not allow barging, which means that once function \code{bar} releases the monitor, \code{foo} is guaranteed to resume immediately after (unless some other thread waited on the same condition). This guarantee offers the benefit of not having to loop around waits to recheck that a condition is met. The main reason \CFA offers this guarantee is that users can easily introduce barging if it becomes a necessity but adding barging prevention or barging avoidance is more involved without language support. Supporting barging prevention as well as extending internal scheduling to multiple monitors is the main source of complexity in the design and implementationof \CFA concurrency.258 259 % ====================================================================== 260 % ====================================================================== 261 \subsection{Internal Scheduling - Multi-Monitor}262 % ====================================================================== 263 % ====================================================================== 264 It is easier to understand the problem of multi-monitor scheduling using a series of pseudo-code examples. Note that for simplicity in the following snippets of pseudo-code, waiting and signalling is done using an implicit condition variable, like Java built-in monitors. Indeed, \code{wait} statements always use the implicit condition variable as parameter sand explicitly names the monitors (A and B) associated with the condition. Note that in \CFA, condition variables are tied to a \emph{group} of monitors on first use (called branding), which means that using internal scheduling with distinct sets of monitors requires one condition variable per set of monitors. The example below shows the simple case of having two threads (one for each column) and a single monitor A.255 There are two details to note here. First, the \code{signal} is a delayed operation, it only unblocks the waiting thread when it reaches the end of the critical section. This semantic is needed to respect mutual-exclusion, i.e., the signaller and signalled thread cannot be in the monitor simultaneously. The alternative is to return immediately after the call to \code{signal}, which is significantly more restrictive. Second, in \CFA, while it is common to store a \code{condition} as a field of the monitor, a \code{condition} variable can be stored/created independently of a monitor. Here routine \code{foo} waits for the \code{signal} from \code{bar} before making further progress, effectively ensuring a basic ordering. 256 257 An important aspect of the implementation is that \CFA does not allow barging, which means that once function \code{bar} releases the monitor, \code{foo} is guaranteed to resume immediately after (unless some other thread waited on the same condition). This guarantee offers the benefit of not having to loop around waits to recheck that a condition is met. The main reason \CFA offers this guarantee is that users can easily introduce barging if it becomes a necessity but adding barging prevention or barging avoidance is more involved without language support. Supporting barging prevention as well as extending internal scheduling to multiple monitors is the main source of complexity in the design of \CFA concurrency. 258 259 % ====================================================================== 260 % ====================================================================== 261 \subsection{Internal Scheduling - multi monitor} 262 % ====================================================================== 263 % ====================================================================== 264 It is easier to understand the problem of multi-monitor scheduling using a series of pseudo-code examples. Note that for simplicity in the following snippets of pseudo-code, waiting and signalling is done using an implicit condition variable, like Java built-in monitors. Indeed, \code{wait} statements always use the implicit condition variable as parameter and explicitly names the monitors (A and B) associated with the condition. Note that in \CFA, condition variables are tied to a \emph{group} of monitors on first use (called branding), which means that using internal scheduling with distinct sets of monitors requires one condition variable per set of monitors. The example below shows the simple case of having two threads (one for each column) and a single monitor A. 265 265 266 266 \begin{multicols}{2} … … 297 297 \end{pseudo} 298 298 \end{multicols} 299 \noindent This version uses \gls{bulk-acq} (denoted using the {\sf\&} symbol), but the presence of multiple monitors does not add a particularly new meaning. Synchronization happens between the two threads in exactly the same way and order. The only difference is that mutual exclusion covers a group ofmonitors. On the implementation side, handling multiple monitors does add a degree of complexity as the next few examples demonstrate.300 301 While deadlock issues can occur when nesting monitors, these issues are only a symptom of the fact that locks, and by extension monitors, are not perfectly composable. For monitors, a well -known deadlock problem is the Nested Monitor Problem~\cite{Lister77}, which occurs when a \code{wait} is made by a thread that holds more than one monitor. For example, the following pseudo-code runs into the nested-monitor problem :299 This version uses \gls{bulk-acq} (denoted using the {\sf\&} symbol), but the presence of multiple monitors does not add a particularly new meaning. Synchronization happens between the two threads in exactly the same way and order. The only difference is that mutual exclusion covers more monitors. On the implementation side, handling multiple monitors does add a degree of complexity as the next few examples demonstrate. 300 301 While deadlock issues can occur when nesting monitors, these issues are only a symptom of the fact that locks, and by extension monitors, are not perfectly composable. For monitors, a well known deadlock problem is the Nested Monitor Problem~\cite{Lister77}, which occurs when a \code{wait} is made by a thread that holds more than one monitor. For example, the following pseudo-code runs into the nested-monitor problem : 302 302 \begin{multicols}{2} 303 303 \begin{pseudo} … … 319 319 \end{pseudo} 320 320 \end{multicols} 321 \noindentThe \code{wait} only releases monitor \code{B} so the signalling thread cannot acquire monitor \code{A} to get to the \code{signal}. Attempting release of all acquired monitors at the \code{wait} introduces a different set of problems, such as releasing monitor \code{C}, which has nothing to do with the \code{signal}.321 The \code{wait} only releases monitor \code{B} so the signalling thread cannot acquire monitor \code{A} to get to the \code{signal}. Attempting release of all acquired monitors at the \code{wait} introduces a different set of problems, such as releasing monitor \code{C}, which has nothing to do with the \code{signal}. 322 322 323 323 However, for monitors as for locks, it is possible to write a program using nesting without encountering any problems if nesting is done correctly. For example, the next pseudo-code snippet acquires monitors {\sf A} then {\sf B} before waiting, while only acquiring {\sf B} when signalling, effectively avoiding the Nested Monitor Problem~\cite{Lister77}. … … 343 343 \end{multicols} 344 344 345 \noindent However, this simple refactoring may not be possible, forcing more complex restructuring.346 347 % ====================================================================== 348 % ====================================================================== 349 \subsection{Internal Scheduling - In Depth}350 % ====================================================================== 351 % ====================================================================== 352 353 A larger example is presented to show complex issues for \gls{bulk-acq} and all the implementation options are analyzed. Listing \ref{lst:int-bulk-pseudo} shows an example where \gls{bulk-acq} adds a significant layer of complexity to the internal signalling semantics, and listing \ref{lst:int-bulk-cfa} shows the corresponding \CFA code to implement the pseudo-code in listing \ref{lst:int-bulk-pseudo}. For the purpose of translating the given pseudo-code into \CFA-code, any method of introducing a monitor is acceptable, e.g., \code{mutex} parameter s, global variables, pointer parameters,or using locals with the \code{mutex}-statement.345 This simple refactoring may not be possible, forcing more complex restructuring. 346 347 % ====================================================================== 348 % ====================================================================== 349 \subsection{Internal Scheduling - in depth} 350 % ====================================================================== 351 % ====================================================================== 352 353 A larger example is presented to show complex issues for \gls{bulk-acq} and all the implementation options are analyzed. Listing \ref{lst:int-bulk-pseudo} shows an example where \gls{bulk-acq} adds a significant layer of complexity to the internal signalling semantics, and listing \ref{lst:int-bulk-cfa} shows the corresponding \CFA code to implement the pseudo-code in listing \ref{lst:int-bulk-pseudo}. For the purpose of translating the given pseudo-code into \CFA-code, any method of introducing a monitor is acceptable, e.g., \code{mutex} parameter, global variables, pointer parameters or using locals with the \code{mutex}-statement. 354 354 355 355 \begin{figure}[!t] … … 376 376 |\label{line:signal1}|signal A & B 377 377 //Code Section 7 378 |\label{line:releaseFirst}|release A & B378 release A & B 379 379 //Code Section 8 380 380 |\label{line:lastRelease}|release A … … 446 446 \end{figure} 447 447 448 The complexity begins at code sections 4 and 8 in listing \ref{lst:int-bulk-pseudo}, which are where the existing semantics of internal scheduling needs to be extended for multiple monitors. The root of the problem is that \gls{bulk-acq} is used in a context where one of the monitors is already acquired and is why it is important to define the behaviour of the previous pseudo-code. When the signaller thread reaches the location where it should ``release \code{A & B}'' (listing \ref{lst:int-bulk-pseudo} line \ref{line:releaseFirst}), it must actually transfer ownership of monitor \code{B} to the waiting thread. This ownership transfer is required in order to prevent barging into \code{B} by another thread, since both the signalling and signalled threads still need monitor \code{A}. There are three options. 449 450 \subsubsection{Delaying Signals} 451 The obvious solution to solve the problem of multi-monitor scheduling is to keep ownership of all locks until the last lock is ready to be transferred. It can be argued that that moment is when the last lock is no longer needed because this semantics fits most closely to the behaviour of single-monitor scheduling. This solution has the main benefit of transferring ownership of groups of monitors, which simplifies the semantics from multiple objects to a single group of objects, effectively making the existing single-monitor semantic viable by simply changing monitors to monitor groups. This solution releases the monitors once every monitor in a group can be released. However, since some monitors are never released (i.e., the monitor of a thread), this interpretation means a group might never be released. A more interesting interpretation is to transfer the group until it can be disbanded, which means the group is not passed further and a thread can retain its locks. 452 453 However, listing \ref{lst:int-secret} shows this solution can become much more complicated depending on what is executed while secretly holding B at line \ref{line:secret}, while avoiding the need to transfer ownership of a subset of the condition monitors. Listing \ref{lst:dependency} shows a slightly different example where a third thread is waiting on monitor \code{A}, using a different condition variable. Because the third thread is signalled when secretly holding \code{B}, the goal becomes unreachable. Depending on the order of signals (listing \ref{lst:dependency} line \ref{line:signal-ab} and \ref{line:signal-a}) two cases can happen : 448 The complexity begins at code sections 4 and 8, which are where the existing semantics of internal scheduling need to be extended for multiple monitors. The root of the problem is that \gls{bulk-acq} is used in a context where one of the monitors is already acquired and is why it is important to define the behaviour of the previous pseudo-code. When the signaller thread reaches the location where it should ``release \code{A & B}'' (listing \ref{lst:int-bulk-pseudo} line \ref{line:signal1}), it must actually transfer ownership of monitor \code{B} to the waiting thread. This ownership transfer is required in order to prevent barging into \code{B} by another thread, since both the signalling and signalled threads still need monitor \code{A}. There are three options. 449 450 \subsubsection{Delaying signals} 451 The obvious solution to solve the problem of multi-monitor scheduling is to keep ownership of all locks until the last lock is ready to be transferred. It can be argued that that moment is when the last lock is no longer needed because this semantics fits most closely to the behaviour of single-monitor scheduling. This solution has the main benefit of transferring ownership of groups of monitors, which simplifies the semantics from multiple objects to a single group of objects, effectively making the existing single-monitor semantic viable by simply changing monitors to monitor groups. The naive approach to this solution is to only release monitors once every monitor in a group can be released. However, since some monitors are never released (i.e., the monitor of a thread), this interpretation means groups can grow but may never shrink. A more interesting interpretation is to only transfer groups as one but to recreate the groups on every operation, i.e., limit ownership transfer to one per \code{signal}/\code{release}. 452 453 However, this solution can become much more complicated depending on what is executed while secretly holding B (listing \ref{lst:int-secret} line \ref{line:secret}). 454 The goal in this solution is to avoid the need to transfer ownership of a subset of the condition monitors. However, listing \ref{lst:dependency} shows a slightly different example where a third thread is waiting on monitor \code{A}, using a different condition variable. Because the third thread is signalled when secretly holding \code{B}, the goal becomes unreachable. Depending on the order of signals (listing \ref{lst:dependency} line \ref{line:signal-ab} and \ref{line:signal-a}) two cases can happen : 454 455 455 456 \paragraph{Case 1: thread $\alpha$ goes first.} In this case, the problem is that monitor \code{A} needs to be passed to thread $\beta$ when thread $\alpha$ is done with it. … … 459 460 Note that ordering is not determined by a race condition but by whether signalled threads are enqueued in FIFO or FILO order. However, regardless of the answer, users can move line \ref{line:signal-a} before line \ref{line:signal-ab} and get the reverse effect for listing \ref{lst:dependency}. 460 461 461 In both cases, the threads need to be able to distinguish, on a per monitor basis, which ones need to be released and which ones need to be transferred, which means knowing when to dispand a group becomes complex and inefficient (see next section)and therefore effectively precludes this approach.462 In both cases, the threads need to be able to distinguish, on a per monitor basis, which ones need to be released and which ones need to be transferred, which means monitors cannot be handled as a single homogeneous group and therefore effectively precludes this approach. 462 463 463 464 \subsubsection{Dependency graphs} … … 501 502 \end{figure} 502 503 503 In listing \ref{lst:int-bulk-pseudo}, there is a solution that satisfies both barging prevention and mutual exclusion. If ownership of both monitors is transferred to the waiter when the signaller releases \code{A & B} and then the waiter transfers back ownership of \code{A} back to the signaller when it releases it, then the problem is solved (\code{B} is no longer in use at this point). Dynamically finding the correct order is therefore the second possible solution. The problem is effectively resolving a dependency graph of ownership requirements. Here even the simplest of code snippets requires two transfers and it seems to increase in a manner close to polynomial. This complexity explosion can be seen in listing \ref{lst:explosion}, which is just a direct extension to three monitors, requires at least three ownership transfer and has multiple solutions. Furthermore, the presence of multiple solutions for ownership transfer can cause deadlock problems if a specific solution is not consistently picked; In the same way that multiple lock acquiring order can cause deadlocks.504 In the listing \ref{lst:int-bulk-pseudo} pseudo-code, there is a solution that satisfies both barging prevention and mutual exclusion. If ownership of both monitors is transferred to the waiter when the signaller releases \code{A & B} and then the waiter transfers back ownership of \code{A} back to the signaller when it releases it, then the problem is solved (\code{B} is no longer in use at this point). Dynamically finding the correct order is therefore the second possible solution. The problem is effectively resolving a dependency graph of ownership requirements. Here even the simplest of code snippets requires two transfers and it seems to increase in a manner close to polynomial. This complexity explosion can be seen in listing \ref{lst:explosion}, which is just a direct extension to three monitors, requires at least three ownership transfer and has multiple solutions. Furthermore, the presence of multiple solutions for ownership transfer can cause deadlock problems if a specific solution is not consistently picked; In the same way that multiple lock acquiring order can cause deadlocks. 504 505 \begin{figure} 505 506 \begin{multicols}{2} … … 530 531 \end{figure} 531 532 532 Given the three threads example in listing \ref{lst:dependency}, figure \ref{fig:dependency} shows the corresponding dependency graph that results, where every node is a statement of one of the three threads, and the arrows the dependency of that statement (e.g., $\alpha1$ must happen before $\alpha2$). The extra challenge is that this dependency graph is effectively post-mortem, but the runtime system needs to be able to build and solve these graphs as the dependency unfolds. Resolving dependency graphs being a complex and expensive endeavour, this solution is not the preferred one.533 534 \subsubsection{Partial Signalling} \label{partial-sig}535 Finally, the solution that is chosen for \CFA is to use partial signalling. Again using listing \ref{lst:int-bulk-pseudo}, the partial signalling solution transfers ownership of monitor \code{B} at lines \ref{line:signal1} to the waiter but does not wake the waiting thread since it is still using monitor \code{A}. Only when it reaches line \ref{line:lastRelease} does it actually wake up the waiting thread. This solution has the benefit that complexity is encapsulated into only two actions, passing monitors to the next owner when they should be released and conditionally waking threads if all conditions are met. This solution has a much simpler implementation than a dependency graph solving algorithms, which is why it was chosen. Furthermore, after being fully implemented, this solution does not appear to have any significant downsides.536 537 Using partial signalling, listing \ref{lst:dependency} can be solved easily:533 Listing \ref{lst:dependency} is the three threads example used in the delayed signals solution. Figure \ref{fig:dependency} shows the corresponding dependency graph that results, where every node is a statement of one of the three threads, and the arrows the dependency of that statement (e.g., $\alpha1$ must happen before $\alpha2$). The extra challenge is that this dependency graph is effectively post-mortem, but the runtime system needs to be able to build and solve these graphs as the dependency unfolds. Resolving dependency graphs being a complex and expensive endeavour, this solution is not the preferred one. 534 535 \subsubsection{Partial signalling} \label{partial-sig} 536 Finally, the solution that is chosen for \CFA is to use partial signalling. Again using listing \ref{lst:int-bulk-pseudo}, the partial signalling solution transfers ownership of monitor \code{B} at lines \ref{line:signal1} to the waiter but does not wake the waiting thread since it is still using monitor \code{A}. Only when it reaches line \ref{line:lastRelease} does it actually wakeup the waiting thread. This solution has the benefit that complexity is encapsulated into only two actions, passing monitors to the next owner when they should be released and conditionally waking threads if all conditions are met. This solution has a much simpler implementation than a dependency graph solving algorithm, which is why it was chosen. Furthermore, after being fully implemented, this solution does not appear to have any significant downsides. 537 538 While listing \ref{lst:dependency} is a complicated problem for previous solutions, it can be solved easily with partial signalling : 538 539 \begin{itemize} 539 540 \item When thread $\gamma$ reaches line \ref{line:release-ab} it transfers monitor \code{B} to thread $\alpha$ and continues to hold monitor \code{A}. 540 541 \item When thread $\gamma$ reaches line \ref{line:release-a} it transfers monitor \code{A} to thread $\beta$ and wakes it up. 541 542 \item When thread $\beta$ reaches line \ref{line:release-aa} it transfers monitor \code{A} to thread $\alpha$ and wakes it up. 543 \item Problem solved! 542 544 \end{itemize} 543 545 … … 652 654 An important note is that, until now, signalling a monitor was a delayed operation. The ownership of the monitor is transferred only when the monitor would have otherwise been released, not at the point of the \code{signal} statement. However, in some cases, it may be more convenient for users to immediately transfer ownership to the thread that is waiting for cooperation, which is achieved using the \code{signal_block} routine. 653 655 654 The example in table \ref{tbl:datingservice} highlights the difference in behaviour. As mentioned, \code{signal} only transfers ownership once the current critical section exits, this behaviour requires additional synchronization when a two-way handshake is needed. To avoid this explicit synchronization, the \code{condition} type offers the \code{signal_block} routine, which handles the two-way handshake as shown in the example. This feature removes the need for a second condition variables and simplifies programming. Like every other monitor semantic, \code{signal_block} uses barging prevention, which means mutual-exclusion is baton-passed both on the frond end and the backend of the call to \code{signal_block}, meaning no other thread can acquire the monitor either before or after the call.656 The example in table \ref{tbl:datingservice} highlights the difference in behaviour. As mentioned, \code{signal} only transfers ownership once the current critical section exits, this behaviour requires additional synchronization when a two-way handshake is needed. To avoid this explicit synchronization, the \code{condition} type offers the \code{signal_block} routine, which handles the two-way handshake as shown in the example. This feature removes the need for a second condition variables and simplifies programming. Like every other monitor semantic, \code{signal_block} uses barging prevention, which means mutual-exclusion is baton-passed both on the frond-end and the back-end of the call to \code{signal_block}, meaning no other thread can acquire the monitor either before or after the call. 655 657 656 658 % ====================================================================== … … 721 723 \end{tabular} 722 724 \end{center} 723 This method is more constrained and explicit, which helps users reduce the non-deterministic nature of concurrency. Indeed, as the following examples demonstrates, external scheduling allows users to wait for events from other threads without the concern of unrelated events occurring. External scheduling can generally be done either in terms of control flow (e.g., Ada with \code{accept}, \uC with \code{_Accept}) or in terms of data (e.g., Go with channels). Of course, both of these paradigms have their own strengths and weaknesses, but for this project control-flow semantics w aschosen to stay consistent with the rest of the languages semantics. Two challenges specific to \CFA arise when trying to add external scheduling with loose object definitions and multiple-monitor routines. The previous example shows a simple use \code{_Accept} versus \code{wait}/\code{signal} and its advantages. Note that while other languages often use \code{accept}/\code{select} as the core external scheduling keyword, \CFA uses \code{waitfor} to prevent name collisions with existing socket \acrshort{api}s.724 725 For the \code{P} member above using internal scheduling, the call to \code{wait} only guarantees that \code{V} is the last routine to access the monitor, allowing a third routine, say \code{isInUse()}, acquire mutual exclusion several times while routine \code{P} is waiting. On the other hand, external scheduling guarantees that while routine \code{P} is waiting, no other routinethan \code{V} can acquire the monitor.726 727 % ====================================================================== 728 % ====================================================================== 729 \subsection{Loose Object Definitions}730 % ====================================================================== 731 % ====================================================================== 732 In \uC, a monitor class declaration include san exhaustive list of monitor operations. Since \CFA is not object oriented, monitors become both more difficult to implement and less clear for a user:725 This method is more constrained and explicit, which helps users reduce the non-deterministic nature of concurrency. Indeed, as the following examples demonstrates, external scheduling allows users to wait for events from other threads without the concern of unrelated events occurring. External scheduling can generally be done either in terms of control flow (e.g., Ada with \code{accept}, \uC with \code{_Accept}) or in terms of data (e.g., Go with channels). Of course, both of these paradigms have their own strengths and weaknesses, but for this project control-flow semantics were chosen to stay consistent with the rest of the languages semantics. Two challenges specific to \CFA arise when trying to add external scheduling with loose object definitions and multiple-monitor routines. The previous example shows a simple use \code{_Accept} versus \code{wait}/\code{signal} and its advantages. Note that while other languages often use \code{accept}/\code{select} as the core external scheduling keyword, \CFA uses \code{waitfor} to prevent name collisions with existing socket \acrshort{api}s. 726 727 For the \code{P} member above using internal scheduling, the call to \code{wait} only guarantees that \code{V} is the last routine to access the monitor, allowing a third routine, say \code{isInUse()}, acquire mutual exclusion several times while routine \code{P} is waiting. On the other hand, external scheduling guarantees that while routine \code{P} is waiting, no routine other than \code{V} can acquire the monitor. 728 729 % ====================================================================== 730 % ====================================================================== 731 \subsection{Loose object definitions} 732 % ====================================================================== 733 % ====================================================================== 734 In \uC, a monitor class declaration includee an exhaustive list of monitor operations. Since \CFA is not object oriented, monitors become both more difficult to implement and less clear for a user: 733 735 734 736 \begin{cfacode} … … 746 748 \end{cfacode} 747 749 748 Furthermore, external scheduling is an example where implementation constraints become visible from the interface. Here is the pseudo -code for the entering phase of a monitor:750 Furthermore, external scheduling is an example where implementation constraints become visible from the interface. Here is the pseudo code for the entering phase of a monitor: 749 751 \begin{center} 750 752 \begin{tabular}{l} … … 761 763 \end{tabular} 762 764 \end{center} 763 For the first two conditions, it is easy to implement a check that can evaluate the condition in a few instruction s. However, a fast check for \pscode{monitor accepts me} is much harder to implement depending on the constraints put on the monitors. Indeed, monitors are often expressed as an entry queue and some acceptor queue as in the following figure:765 For the first two conditions, it is easy to implement a check that can evaluate the condition in a few instruction. However, a fast check for \pscode{monitor accepts me} is much harder to implement depending on the constraints put on the monitors. Indeed, monitors are often expressed as an entry queue and some acceptor queue as in the following figure: 764 766 765 767 \begin{figure}[H] … … 770 772 \end{figure} 771 773 772 There are other alternatives to these pictures, but in the case of this picture, implementing a fast accept check is relatively easy. Restricted to a fixed number of mutex members, N, the accept check reduces to updating a bitmask when the acceptor queue changes, a check that executes in a single instruction even with a fairly large number (e.g., 128) of mutex members. This approach requires a unique dense ordering of routines with an upper-bound and that ordering must be consistent across translation units. For OO languages these constraints are common, since objects only offer adding member routines consistently across translation units via inheritance. However, in \CFA users can extend objects with mutex routines that are only visible in certain translation unit. This means that establishing a program-wide dense-ordering among mutex routines can only be done in the program linking phase, and still could have issues when using dynamically shared objects.774 There are other alternatives to these pictures, but in the case of this picture, implementing a fast accept check is relatively easy. Restricted to a fixed number of mutex members, N, the accept check reduces to updating a bitmask when the acceptor queue changes, a check that executes in a single instruction even with a fairly large number (e.g., 128) of mutex members. This approach requires a dense unique ordering of routines with an upper-bound and that ordering must be consistent across translation units. For OO languages these constraints are common, since objects only offer adding member routines consistently across translation units via inheritence. However, in \CFA users can extend objects with mutex routines that are only visible in certain translation unit. This means that establishing a program-wide dense-ordering among mutex routines can only be done in the program linking phase, and still could have issues when using dynamically shared objects. 773 775 774 776 The alternative is to alter the implementation like this: 777 775 778 \begin{center} 776 779 {\resizebox{0.4\textwidth}{!}{\input{ext_monitor}}} 777 780 \end{center} 778 Here, the mutex routine called is associated with a thread on the entry queue while a list of acceptable routines is kept separate. Generating a mask dynamically means that the storage for the mask information can vary between calls to \code{waitfor}, allowing for more flexibility and extensions. Storing an array of accepted function pointers replaces the single instruction bitmask comparison with dereferencing a pointer followed by a linear search. Furthermore, supporting nested external scheduling (e.g., listing \ref{lst:nest-ext}) may now require additional searches for the \code{waitfor} statement to check if a routine is already queued. 781 782 Here, the mutex routine called is associated with a thread on the entry queue while a list of acceptable routines is kept seperately. Generating a mask dynamically means that the storage for the mask information can vary between calls to \code{waitfor}, allowing for more flexibility and extensions. Storing an array of accepted function-pointers replaces the single instruction bitmask compare with dereferencing a pointer followed by a linear search. Furthermore, supporting nested external scheduling (e.g., listing \ref{lst:nest-ext}) may now require additional searches for the \code{waitfor} statement to check if a routine is already queued. 779 783 780 784 \begin{figure} … … 793 797 \end{figure} 794 798 795 Note that in the second picture, tasks need to always keep track of the monitors associated with mutex routines, and the routine mask needs to have both a function pointer and a set of monitors, as is discussed in the next section. These details are omitted from the picture for the sake of simplicity.796 797 At this point, a decision must be made between flexibility and performance. Many design decisions in \CFA achieve both flexibility and performance, for example polymorphic routines add significant flexibility but inlining them means the optimizer can easily remove any runtime cost. Here , however, the cost of flexibility cannot be trivially removed. In the end, the most flexible approach has been chosen since it allows users to write programs that would otherwise be hard to write. This decision is based on the assumption that writing fast but inflexible locks is closer to a solved problemthan writing locks that are as flexible as external scheduling in \CFA.798 799 % ====================================================================== 800 % ====================================================================== 801 \subsection{Multi- Monitor Scheduling}802 % ====================================================================== 803 % ====================================================================== 804 805 External scheduling, like internal scheduling, becomes significantly more complex when introducing multi-monitor syntax. Even in the simplest possible case, some new semantics need sto be established:799 Note that in the second picture, tasks need to always keep track of the monitors associated with mutex routines, and the routine mask needs to have both a function pointer and a set of monitors, as is be discussed in the next section. These details are omitted from the picture for the sake of simplicity. 800 801 At this point, a decision must be made between flexibility and performance. Many design decisions in \CFA achieve both flexibility and performance, for example polymorphic routines add significant flexibility but inlining them means the optimizer can easily remove any runtime cost. Here however, the cost of flexibility cannot be trivially removed. In the end, the most flexible approach has been chosen since it allows users to write programs that would otherwise be hard to write. This decision is based on the assumption that writing fast but inflexible locks is closer to a solved problems than writing locks that are as flexible as external scheduling in \CFA. 802 803 % ====================================================================== 804 % ====================================================================== 805 \subsection{Multi-monitor scheduling} 806 % ====================================================================== 807 % ====================================================================== 808 809 External scheduling, like internal scheduling, becomes significantly more complex when introducing multi-monitor syntax. Even in the simplest possible case, some new semantics need to be established: 806 810 \begin{cfacode} 807 811 monitor M {}; … … 833 837 834 838 void g(M & mutex a, M & mutex b) { 835 //wait for call to f with argument sa and b839 //wait for call to f with argument a and b 836 840 waitfor(f, a, b); 837 841 } … … 866 870 % ====================================================================== 867 871 % ====================================================================== 868 \subsection{\code{waitfor} Semantics}869 % ====================================================================== 870 % ====================================================================== 871 872 Syntactically, the \code{waitfor} statement takes a function identifier and a set of monitors. While the set of monitors can be any list of expression s, the function name is more restricted because the compiler validates at compile time the validity of the function type and the parameters used with the \code{waitfor} statement. It checks that the set of monitors passed in matches the requirements for a function call. Listing \ref{lst:waitfor} shows various usagesof the waitfor statement and which are acceptable. The choice of the function type is made ignoring any non-\code{mutex} parameter. One limitation of the current implementation is that it does not handle overloading but overloading is possible.872 \subsection{\code{waitfor} semantics} 873 % ====================================================================== 874 % ====================================================================== 875 876 Syntactically, the \code{waitfor} statement takes a function identifier and a set of monitors. While the set of monitors can be any list of expression, the function name is more restricted because the compiler validates at compile time the validity of the function type and the parameters used with the \code{waitfor} statement. It checks that the set of monitors passed in matches the requirements for a function call. Listing \ref{lst:waitfor} shows various usage of the waitfor statement and which are acceptable. The choice of the function type is made ignoring any non-\code{mutex} parameter. One limitation of the current implementation is that it does not handle overloading but overloading is possible. 873 877 \begin{figure} 874 878 \begin{cfacode}[caption={Various correct and incorrect uses of the waitfor statement},label={lst:waitfor}] … … 904 908 \end{figure} 905 909 906 Finally, for added flexibility, \CFA supports constructing a complex \code{waitfor} statement using the \code{or}, \code{timeout} and \code{else}. Indeed, multiple \code{waitfor} clauses can be chained together using \code{or}; this chain forms a single statement that uses baton pass to anyfunction that fits one of the function+monitor set passed in. To enable users to tell which accepted function executed, \code{waitfor}s are followed by a statement (including the null statement \code{;}) or a compound statement, which is executed after the clause is triggered. A \code{waitfor} chain can also be followed by a \code{timeout}, to signify an upper bound on the wait, or an \code{else}, to signify that the call should be non-blocking, which checks for a matching function call already arrived and otherwise continues. Any and all of these clauses can be preceded by a \code{when} condition to dynamically toggle the accept clauses on or off based on some current state. Listing \ref{lst:waitfor2}, demonstrates several complex masks and some incorrect ones.910 Finally, for added flexibility, \CFA supports constructing a complex \code{waitfor} statement using the \code{or}, \code{timeout} and \code{else}. Indeed, multiple \code{waitfor} clauses can be chained together using \code{or}; this chain forms a single statement that uses baton-pass to any one function that fits one of the function+monitor set passed in. To enable users to tell which accepted function executed, \code{waitfor}s are followed by a statement (including the null statement \code{;}) or a compound statement, which is executed after the clause is triggered. A \code{waitfor} chain can also be followed by a \code{timeout}, to signify an upper bound on the wait, or an \code{else}, to signify that the call should be non-blocking, which checks for a matching function call already arrived and otherwise continues. Any and all of these clauses can be preceded by a \code{when} condition to dynamically toggle the accept clauses on or off based on some current state. Listing \ref{lst:waitfor2}, demonstrates several complex masks and some incorrect ones. 907 911 908 912 \begin{figure} … … 969 973 % ====================================================================== 970 974 % ====================================================================== 971 \subsection{Waiting For The Destructor}972 % ====================================================================== 973 % ====================================================================== 974 An interesting use for the \code{waitfor} statement is destructor semantics. Indeed, the \code{waitfor} statement can accept any \code{mutex} routine, which includes the destructor (see section \ref{data}). However, with the semantics discussed until now, waiting for the destructor does not make any sense since using an object after its destructor is called is undefined behaviour. The simplest approach is to disallow \code{waitfor} on a destructor. However, a more expressive approach is to flip ordering of executionwhen waiting for the destructor, meaning that waiting for the destructor allows the destructor to run after the current \code{mutex} routine, similarly to how a condition is signalled.975 \subsection{Waiting for the destructor} 976 % ====================================================================== 977 % ====================================================================== 978 An interesting use for the \code{waitfor} statement is destructor semantics. Indeed, the \code{waitfor} statement can accept any \code{mutex} routine, which includes the destructor (see section \ref{data}). However, with the semantics discussed until now, waiting for the destructor does not make any sense since using an object after its destructor is called is undefined behaviour. The simplest approach is to disallow \code{waitfor} on a destructor. However, a more expressive approach is to flip execution ordering when waiting for the destructor, meaning that waiting for the destructor allows the destructor to run after the current \code{mutex} routine, similarly to how a condition is signalled. 975 979 \begin{figure} 976 980 \begin{cfacode}[caption={Example of an executor which executes action in series until the destructor is called.},label={lst:dtor-order}] -
doc/proposals/concurrency/text/frontpgs.tex
rc13e8dc8 r9c35431 80 80 \begin{center}\textbf{Abstract}\end{center} 81 81 82 \CFA is a modern, non-object-oriented extension of the C programming language. This thesis serves as a definition and an implementation for the concurrency and parallelism \CFA offers. These features are created from scratch due to the lack of concurrency in ISO C. Lightweight threads are introduced into the language. In addition, monitors are introduced as a high-level tool for control-flow based synchronization and mutual-exclusion. The main contributions of this thesis are two-fold: it extends the existing semantics of monitors introduce by~\cite{Hoare74} to handle monitors in groups and also details the engineering effort needed to introduce these features as core language features. Indeed, these features are added with respect to expectations of C programmers, and integrate with the \CFA type-system and other language features.82 \CFA is a modern, non-object-oriented extension of the C programming language. This thesis serves as a definition and an implementation for the concurrency and parallelism \CFA offers. These features are created from scratch due to the lack of concurrency in ISO C. Monitors are introduced as a high-level tool for control-flow based concurrency. In addition, lightweight threads are also introduced into the language. Specifically, the contribution of this thesis is two-fold: it extends the existing semantics of monitors introduce by~\cite{Hoare74} to handle monitors in groups and also details the engineering effort needed to introduce these features as core language features. Indeed, these features are added in respect with expectations of C programmers and are backwards compatible as much as possible. 83 83 84 84 … … 95 95 I would like to thank Professors Martin Karsten and Gregor Richards, for reading my thesis and providing helpful feedback. 96 96 97 Thanks to Aaron Moss, Rob Schluntz and Andrew Beach for their work on the \CFA project as well as all the discussions which have help edme concretize the ideas in this thesis.97 Thanks to Aaron Moss, Rob Schluntz and Andrew Beach for their work on the \CFA project as well as all the discussions which have help me concretize the ideas in this thesis. 98 98 99 Finally, I acknowledge that this has been possible thanks to the financial help offered by the David R. Cheriton School of Computer Science and the corporate partnership with Huawei Ltd.99 Finally, I acknowledge that this as been possible thanks to the financial help offered by the David R. Cheriton School of Computer Science and the corperate partnership with Huawei Ltd. 100 100 101 101 \cleardoublepage -
doc/proposals/concurrency/text/future.tex
rc13e8dc8 r9c35431 1 1 2 2 \chapter{Conclusion} 3 This thesis has achieved a minimal concurrency \acrshort{api} that is simple, efficient and usable as the basis for higher-level features. The approach presented is based on a lightweight thread-system for parallelism, which sits on top of clusters of processors. This M:N model is judged to be both more efficient and allow more flexibility for users. Furthermore, this document introduces monitors as the main concurrency tool for users. This thesis also offers a novel approach allowing multiple monitors to be accessed simultaneously without running into the Nested Monitor Problem~\cite{Lister77}. It also offers a full implementation of the concurrency runtime written entirely in \CFA, effectively the largest \CFA code base to date.3 As mentionned in the introduction, this thesis provides a minimal concurrency \acrshort{api} that is simple, efficient and usable as the basis for higher-level features. The approach presented is based on a lighweight thread system for parallelism which sits on top of clusters of processors. This M:N model is jugded to be both more efficient and allow more flexibility for users. Furthermore, this document introduces monitors as the main concurrency tool for users. This thesis also offers a novel approach which allows using multiple monitors at once without running into the Nested Monitor Problem~\cite{Lister77}. It also offers a full implmentation of the concurrency runtime wirtten enterily in \CFA, effectively the largest \CFA code base to date. 4 4 5 5 … … 11 11 12 12 \subsection{Performance} \label{futur:perf} 13 This thesis presents a first implementation of the \CFA runtime. Therefore, there is still significant work to improve performance. Many of the data structures and algorithms may change in the future to more efficient versions. For example, the number of monitors in a single \gls{bulk-acq} is only bound by the stack size, this is probably unnecessarily generous. It may be possible that limiting the number helpsincrease performance. However, it is not obvious that the benefit would be significant.13 This thesis presents a first implementation of the \CFA runtime. Therefore, there is still significant work to do to improve performance. Many of the data structures and algorithms will change in the future to more efficient versions. For example, \CFA the number of monitors in a single \gls{bulk-acq} is only bound by the stack size, this is probably unnecessarily generous. It may be possible that limiting the number help increase performance. However, it is not obvious that the benefit would be significant. 14 14 15 15 \subsection{Flexible Scheduling} \label{futur:sched} 16 An important part of concurrency is scheduling. Different scheduling algorithm s can affect performance (both in terms of average and variation). However, no single scheduler is optimal for all workloads and therefore there is value in being able to change the scheduler for given programs. One solution is to offer various tweaking options to users, allowing the scheduler to be adjusted to the requirements of the workload. However, in order to be truly flexible, it would be interesting to allow users to add arbitrary data and arbitrary scheduling algorithms. For example, a web server could attach Type-of-Service information to threads and have a ``ToS aware'' scheduling algorithm tailored to this specific web server. This path of flexible schedulers will be explored for \CFA.16 An important part of concurrency is scheduling. Different scheduling algorithm can affect performance (both in terms of average and variation). However, no single scheduler is optimal for all workloads and therefore there is value in being able to change the scheduler for given programs. One solution is to offer various tweaking options to users, allowing the scheduler to be adjusted to the requirements of the workload. However, in order to be truly flexible, it would be interesting to allow users to add arbitrary data and arbitrary scheduling algorithms to the scheduler. For example, a web server could attach Type-of-Service information to threads and have a ``ToS aware'' scheduling algorithm tailored to this specific web server. This path of flexible schedulers will be explored for \CFA. 17 17 18 18 \subsection{Non-Blocking IO} \label{futur:nbio} 19 While most of the parallelism tools are aimed at data parallelism and control-flow parallelism, many modern workloads are not bound on computation but on IO operations, a common case being web servers and XaaS (anything as a service). These types of workloads often require significant engineering around amortizing costs of blocking IO operations. At its core, Non-Blocking IO is an operating system level feature that allows queuing IO operations (e.g., network operations) and registering for notifications instead of waiting for requests to complete. In this context, the role of the language makesNon-Blocking IO easily available and with low overhead. The current trend is to use asynchronous programming using tools like callbacks and/or futures and promises, which can be seen in frameworks like Node.js~\cite{NodeJs} for JavaScript, Spring MVC~\cite{SpringMVC} for Java and Django~\cite{Django} for Python. However, while these are valid solutions, they lead to code that is harder to read and maintain because it is much less linear.19 While most of the parallelism tools are aimed at data parallelism and control-flow parallelism, many modern workloads are not bound on computation but on IO operations, a common case being web-servers and XaaS (anything as a service). These type of workloads often require significant engineering around amortizing costs of blocking IO operations. At its core, Non-Blocking IO is a operating system level feature that allows queuing IO operations (e.g., network operations) and registering for notifications instead of waiting for requests to complete. In this context, the role of the language make Non-Blocking IO easily available and with low overhead. The current trend is to use asynchronous programming using tools like callbacks and/or futures and promises, which can be seen in frameworks like Node.js~\cite{NodeJs} for JavaScript, Spring MVC~\cite{SpringMVC} for Java and Django~\cite{Django} for Python. However, while these are valid solutions, they lead to code that is harder to read and maintain because it is much less linear. 20 20 21 \subsection{Other Concurrency Tools} \label{futur:tools}22 While monitors offer a flexible and powerful concurrent core for \CFA, other concurrency tools are also necessary for a complete multi-paradigm concurrency package. Example sof such tools can include simple locks and condition variables, futures and promises~\cite{promises}, executors and actors. These additional features are useful when monitors offer a level of abstraction that is inadequate for certain tasks.21 \subsection{Other concurrency tools} \label{futur:tools} 22 While monitors offer a flexible and powerful concurrent core for \CFA, other concurrency tools are also necessary for a complete multi-paradigm concurrency package. Example of such tools can include simple locks and condition variables, futures and promises~\cite{promises}, executors and actors. These additional features are useful when monitors offer a level of abstraction that is inadequate for certain tasks. 23 23 24 \subsection{Implicit Threading} \label{futur:implcit}25 Simpler applications can benefit greatly from having implicit parallelism. That is, parallelism that does not rely on the user to write concurrency. This type of parallelism can be achieved both at the language level and at the library level. The canonical example of implicit parallelism is parallel for loops, which are the simplest example of a divide and conquer algorithm s~\cite{uC++book}. Table \ref{lst:parfor} shows three different code examples that accomplish point-wise sums of large arrays. Note that none of these examples explicitly declare any concurrency or parallelism objects.24 \subsection{Implicit threading} \label{futur:implcit} 25 Simpler applications can benefit greatly from having implicit parallelism. That is, parallelism that does not rely on the user to write concurrency. This type of parallelism can be achieved both at the language level and at the library level. The canonical example of implicit parallelism is parallel for loops, which are the simplest example of a divide and conquer algorithm~\cite{uC++book}. Table \ref{lst:parfor} shows three different code examples that accomplish point-wise sums of large arrays. Note that none of these examples explicitly declare any concurrency or parallelism objects. 26 26 27 27 \begin{table} … … 108 108 \end{table} 109 109 110 Implicit parallelism is a restrictive solution and therefore has its limitations. However, it is a quick and simple approach to parallelism, which may very well be sufficient for smaller applications and reduces the amount of boiler plate needed to start benefiting from parallelism in modern CPUs.110 Implicit parallelism is a restrictive solution and therefore has its limitations. However, it is a quick and simple approach to parallelism, which may very well be sufficient for smaller applications and reduces the amount of boiler-plate needed to start benefiting from parallelism in modern CPUs. 111 111 112 112 -
doc/proposals/concurrency/text/internals.tex
rc13e8dc8 r9c35431 1 1 2 \chapter{Behind the Scenes}3 There are several challenges specific to \CFA when implementing concurrency. These challenges are a direct result of \gls{bulk-acq} and loose object definitions. These two constraints are the root cause of most design decisions in the implementation. Furthermore, to avoid contention from dynamically allocating memory in a concurrent environment, the internal-scheduling design is (almost) entirely free of mallocs. This approach avoids the chicken and egg problem~\cite{Chicken} of having a memory allocator that relies on the threading system and a threading system that relies on the runtime. This extra goal means that memory management is a constant concern in the design of the system.4 5 The main memory concern for concurrency is queues. All blocking operations are made by parking threads onto queues and all queues are designed with intrusive nodes, where each no de has pre-allocated link fields for chaining, to avoid the need for memory allocation. Since several concurrency operations can use an unbound amount of memory (depending on \gls{bulk-acq}), statically defining information in the intrusive fields of threads is insufficient.The only way to use a variable amount of memory without requiring memory allocation is to pre-allocate large buffers of memory eagerly and store the information in these buffers. Conveniently, the call stack fits that description and is easy to use, which is why it is used heavily in the implementation of internal scheduling, particularly variable-length arrays. Since stack allocation is based on scopes, the first step of the implementation is to identify the scopes that are available to store the information, and which of these can have a variable-length array. The threads and the condition both have a fixed amount of memory, while mute routines and blocking callsallow for an unbound amount, within the stack size.2 \chapter{Behind the scene} 3 There are several challenges specific to \CFA when implementing concurrency. These challenges are a direct result of \gls{bulk-acq} and loose object-definitions. These two constraints are the root cause of most design decisions in the implementation. Furthermore, to avoid contention from dynamically allocating memory in a concurrent environment, the internal-scheduling design is (almost) entirely free of mallocs. This approach avoids the chicken and egg problem~\cite{Chicken} of having a memory allocator that relies on the threading system and a threading system that relies on the runtime. This extra goal means that memory management is a constant concern in the design of the system. 4 5 The main memory concern for concurrency is queues. All blocking operations are made by parking threads onto queues and all queues are designed with intrusive nodes, where each not has pre-allocated link fields for chaining, to avoid the need for memory allocation. Since several concurrency operations can use an unbound amount of memory (depending on \gls{bulk-acq}), statically defining information in the intrusive fields of threads is insufficient.The only way to use a variable amount of memory without requiring memory allocation is to pre-allocate large buffers of memory eagerly and store the information in these buffers. Conveniently, the callstack fits that description and is easy to use, which is why it is used heavily in the implementation of internal scheduling, particularly variable-length arrays. Since stack allocation is based around scope, the first step of the implementation is to identify the scopes that are available to store the information, and which of these can have a variable-length array. The threads and the condition both have a fixed amount of memory, while mutex-routines and the actual blocking call allow for an unbound amount, within the stack size. 6 6 7 7 Note that since the major contributions of this thesis are extending monitor semantics to \gls{bulk-acq} and loose object definitions, any challenges that are not resulting of these characteristics of \CFA are considered as solved problems and therefore not discussed. … … 9 9 % ====================================================================== 10 10 % ====================================================================== 11 \section{Mutex Routines}12 % ====================================================================== 13 % ====================================================================== 14 15 The first step towards the monitor implementation is simple mute routines. In the single monitor case, mutual-exclusion is done using the entry/exit procedure in listing \ref{lst:entry1}. The entry/exit procedures do not have to be extended to support multiple monitors. Indeed it is sufficient to enter/leave monitors one-by-one as long as the order is correct to prevent deadlock~\cite{Havender68}. In \CFA, ordering of monitor acquisition relies on memory ordering. This approach is sufficient because all objects are guaranteed to have distinct non-overlapping memory layouts and mutual-exclusion for a monitor is only defined for its lifetime, meaning that destroying a monitor while it is acquired is Undefined Behaviour. When a mutex call is made, the concerned monitors are aggregated into a variable-length pointerarray and sorted based on pointer values. This array persists for the entire duration of the mutual-exclusion and its ordering reused extensively.11 \section{Mutex routines} 12 % ====================================================================== 13 % ====================================================================== 14 15 The first step towards the monitor implementation is simple mutex-routines. In the single monitor case, mutual-exclusion is done using the entry/exit procedure in listing \ref{lst:entry1}. The entry/exit procedures do not have to be extended to support multiple monitors. Indeed it is sufficient to enter/leave monitors one-by-one as long as the order is correct to prevent deadlock~\cite{Havender68}. In \CFA, ordering of monitor acquisition relies on memory ordering. This approach is sufficient because all objects are guaranteed to have distinct non-overlapping memory layouts and mutual-exclusion for a monitor is only defined for its lifetime, meaning that destroying a monitor while it is acquired is Undefined Behavior. When a mutex call is made, the concerned monitors are aggregated into a variable-length pointer-array and sorted based on pointer values. This array persists for the entire duration of the mutual-exclusion and its ordering reused extensively. 16 16 \begin{figure} 17 17 \begin{multicols}{2} … … 109 109 \end{cfacode} 110 110 111 Both entry point and \gls{callsite-locking} are feasible implementations. The current \CFA implementation uses entry-point locking because it requires less work when using \gls{raii}, effectively transferring the burden of implementation to object construction/destruction. It is harder to use \gls{raii} for call-site locking, as it does not necessarily have an existing scope that matches exactly the scope of the mutual exclusion, i.e.: the function body. For example, the monitor call can appear in the middle of an expression. Furthermore, entry-point locking requires less code generation since any useful routine multiple times, but there is only one entry point for many callsites.111 Both entry-point and \gls{callsite-locking} are feasible implementations. The current \CFA implementations uses entry-point locking because it requires less work when using \gls{raii}, effectively transferring the burden of implementation to object construction/destruction. It is harder to use \gls{raii} for call-site locking, as it does not necessarily have an existing scope that matches exactly the scope of the mutual exclusion, i.e.: the function body. For example, the monitor call can appear in the middle of an expression. Furthermore, entry-point locking requires less code generation since any useful routine multiple times, but there is only one entry-point for many call-sites. 112 112 113 113 % ====================================================================== … … 117 117 % ====================================================================== 118 118 119 Figure \ref{fig:system1} shows a high-level picture if the \CFA runtime system in regards to concurrency. Each component of the picture is explained in detail in the flowing sections.119 Figure \ref{fig:system1} shows a high-level picture if the \CFA runtime system in regards to concurrency. Each component of the picture is explained in details in the flowing sections. 120 120 121 121 \begin{figure} … … 128 128 129 129 \subsection{Context Switching} 130 As mentioned in section \ref{coroutine}, coroutines are a stepping stone for implementing threading, because they share the same mechanism for context-switching between different stacks. To improve performance and simplicity, context-switching is implemented using the following assumption: all context-switches happen inside a specific function call. This assumption means that the context-switch only has to copy the callee-saved registers onto the stack and then switch the stack registers with the ones of the target coroutine/thread. Note that the instruction pointer can be left untouched since the context-switch is always inside the same function. Threads , however, do not context-switch between each other directly. They context-switch to the scheduler. This method is called a 2-step context-switch and has the advantage of having a clear distinction between user code and the kernel where scheduling and other system operationshappen. Obviously, this doubles the context-switch cost because threads must context-switch to an intermediate stack. The alternative 1-step context-switch uses the stack of the ``from'' thread to schedule and then context-switches directly to the ``to'' thread. However, the performance of the 2-step context-switch is still superior to a \code{pthread_yield} (see section \ref{results}). Additionally, for users in need for optimal performance, it is important to note that having a 2-step context-switch as the default does not prevent \CFA from offering a 1-step context-switch (akin to the Microsoft \code{SwitchToFiber}~\cite{switchToWindows} routine). This option is not currently present in \CFA but the changes required to add it are strictly additive.130 As mentioned in section \ref{coroutine}, coroutines are a stepping stone for implementing threading, because they share the same mechanism for context-switching between different stacks. To improve performance and simplicity, context-switching is implemented using the following assumption: all context-switches happen inside a specific function call. This assumption means that the context-switch only has to copy the callee-saved registers onto the stack and then switch the stack registers with the ones of the target coroutine/thread. Note that the instruction pointer can be left untouched since the context-switch is always inside the same function. Threads however do not context-switch between each other directly. They context-switch to the scheduler. This method is called a 2-step context-switch and has the advantage of having a clear distinction between user code and the kernel where scheduling and other system operation happen. Obviously, this doubles the context-switch cost because threads must context-switch to an intermediate stack. The alternative 1-step context-switch uses the stack of the ``from'' thread to schedule and then context-switches directly to the ``to'' thread. However, the performance of the 2-step context-switch is still superior to a \code{pthread_yield} (see section \ref{results}). Additionally, for users in need for optimal performance, it is important to note that having a 2-step context-switch as the default does not prevent \CFA from offering a 1-step context-switch (akin to the Microsoft \code{SwitchToFiber}~\cite{switchToWindows} routine). This option is not currently present in \CFA but the changes required to add it are strictly additive. 131 131 132 132 \subsection{Processors} 133 Parallelism in \CFA is built around using processors to specify how much parallelism is desired. \CFA processors are object wrappers around kernel threads, specifically pthreads in the current implementation of \CFA. Indeed, any parallelism must go through operating-system libraries. However, \glspl{uthread} are still the main source of concurrency, processors are simply the underlying source of parallelism. Indeed, processor \glspl{kthread} simply fetch a \gls{uthread} from the scheduler and run it; they are effectively executers for user-threads. The main benefit of this approach is that it offers a well -defined boundary between kernel code and user code, for example, kernel thread quiescing, scheduling and interrupt handling. Processors internally use coroutines to take advantage of the existing context-switching semantics.134 135 \subsection{Stack Management}136 One of the challenges of this system is to reduce the footprint as much as possible. Specifically, all pthreads created also have a stack created with them, which should be used as much as possible. Normally, coroutines also create there own stack to run on, however, in the case of the coroutines used for processors, these coroutines run directly on the \gls{kthread} stack, effectively stealing the processor stack. The exception to this rule is the Main Processor, i.e. the initial \gls{kthread} that is given to any program. In order to respect C user expectations, the stack of the initial kernel thread, the main stack of the program, is used by the main user thread rather than the main processor, which can grow very large.133 Parallelism in \CFA is built around using processors to specify how much parallelism is desired. \CFA processors are object wrappers around kernel threads, specifically pthreads in the current implementation of \CFA. Indeed, any parallelism must go through operating-system libraries. However, \glspl{uthread} are still the main source of concurrency, processors are simply the underlying source of parallelism. Indeed, processor \glspl{kthread} simply fetch a \gls{uthread} from the scheduler and run it; they are effectively executers for user-threads. The main benefit of this approach is that it offers a well defined boundary between kernel code and user code, for example, kernel thread quiescing, scheduling and interrupt handling. Processors internally use coroutines to take advantage of the existing context-switching semantics. 134 135 \subsection{Stack management} 136 One of the challenges of this system is to reduce the footprint as much as possible. Specifically, all pthreads created also have a stack created with them, which should be used as much as possible. Normally, coroutines also create there own stack to run on, however, in the case of the coroutines used for processors, these coroutines run directly on the \gls{kthread} stack, effectively stealing the processor stack. The exception to this rule is the Main Processor, i.e. the initial \gls{kthread} that is given to any program. In order to respect C user-expectations, the stack of the initial kernel thread, the main stack of the program, is used by the main user thread rather than the main processor, which can grow very large 137 137 138 138 \subsection{Preemption} \label{preemption} 139 Finally, an important aspect for any complete threading system is preemption. As mentioned in chapter \ref{basics}, preemption introduces an extra degree of uncertainty, which enables users to have multiple threads interleave transparently, rather than having to cooperate among threads for proper scheduling and CPU distribution. Indeed, preemption is desirable because it adds a degree of isolation among threads. In a fully cooperative system, any thread that runs a long loop can starve other threads, while in a preemptive system, starvation can still occur but it does not rely on every thread having to yield or block on a regular basis, which reduces significantly a programmer burden. Obviously, preemption is not optimal for every workload . However any preemptive system can become a cooperative system by making the timeslices extremely large. Therefore, \CFA uses a preemptive threading system.139 Finally, an important aspect for any complete threading system is preemption. As mentioned in chapter \ref{basics}, preemption introduces an extra degree of uncertainty, which enables users to have multiple threads interleave transparently, rather than having to cooperate among threads for proper scheduling and CPU distribution. Indeed, preemption is desirable because it adds a degree of isolation among threads. In a fully cooperative system, any thread that runs a long loop can starve other threads, while in a preemptive system, starvation can still occur but it does not rely on every thread having to yield or block on a regular basis, which reduces significantly a programmer burden. Obviously, preemption is not optimal for every workload, however any preemptive system can become a cooperative system by making the time-slices extremely large. Therefore, \CFA uses a preemptive threading system. 140 140 141 141 Preemption in \CFA is based on kernel timers, which are used to run a discrete-event simulation. Every processor keeps track of the current time and registers an expiration time with the preemption system. When the preemption system receives a change in preemption, it inserts the time in a sorted order and sets a kernel timer for the closest one, effectively stepping through preemption events on each signal sent by the timer. These timers use the Linux signal {\tt SIGALRM}, which is delivered to the process rather than the kernel-thread. This results in an implementation problem, because when delivering signals to a process, the kernel can deliver the signal to any kernel thread for which the signal is not blocked, i.e. : … … 146 146 For the sake of simplicity and in order to prevent the case of having two threads receiving alarms simultaneously, \CFA programs block the {\tt SIGALRM} signal on every kernel thread except one. Now because of how involuntary context-switches are handled, the kernel thread handling {\tt SIGALRM} cannot also be a processor thread. 147 147 148 Involuntary context-switching is done by sending signal {\tt SIGUSER1} to the corresponding proces\-sor and having the thread yield from inside the signal handler. This approach effectively context-switches away from the signal handler back to the kernel and the signal-handler frame is eventually unwound when the thread is scheduled again. As a result, a signal-handler can start on one kernel thread and terminate on a second kernel thread (but the same user thread). It is important to note that signal-handlers save and restore signal masks because user-thread migration can cause a signal mask to migrate from one kernel thread to another. This behaviour is only a problem if all kernel threads, among which a user thread can migrate, differ in terms of signal masks\footnote{Sadly, official POSIX documentation is silent on what distinguishes ``async-signal-safe'' functions from other functions.}. However, since the kernel thread handling preemption requires a different signal mask, executing user threads on the kernel-alarm thread can cause deadlocks. For this reason, the alarm thread is in a tight loop around a system call to \code{sigwaitinfo}, requiring very little CPU time for preemption. One final detail about the alarm thread is how to wake it when additional communication is required (e.g., on thread termination). This unblocking is also done using {\tt SIGALRM}, but sent through the \code{pthread_sigqueue}. Indeed, \code{sigwait} can differentiate signals sent from \code{pthread_sigqueue} from signals sent from alarms or the kernel.148 Involuntary context-switching is done by sending signal {\tt SIGUSER1} to the corresponding proces\-sor and having the thread yield from inside the signal handler. This approach effectively context-switches away from the signal-handler back to the kernel and the signal-handler frame is eventually unwound when the thread is scheduled again. As a result, a signal-handler can start on one kernel thread and terminate on a second kernel thread (but the same user thread). It is important to note that signal-handlers save and restore signal masks because user-thread migration can cause a signal mask to migrate from one kernel thread to another. This behaviour is only a problem if all kernel threads, among which a user thread can migrate, differ in terms of signal masks\footnote{Sadly, official POSIX documentation is silent on what distinguishes ``async-signal-safe'' functions from other functions.}. However, since the kernel thread handling preemption requires a different signal mask, executing user threads on the kernel-alarm thread can cause deadlocks. For this reason, the alarm thread is in a tight loop around a system call to \code{sigwaitinfo}, requiring very little CPU time for preemption. One final detail about the alarm thread is how to wake it when additional communication is required (e.g., on thread termination). This unblocking is also done using {\tt SIGALRM}, but sent through the \code{pthread_sigqueue}. Indeed, \code{sigwait} can differentiate signals sent from \code{pthread_sigqueue} from signals sent from alarms or the kernel. 149 149 150 150 \subsection{Scheduler} … … 153 153 % ====================================================================== 154 154 % ====================================================================== 155 \section{Internal Scheduling} \label{impl:intsched}155 \section{Internal scheduling} \label{impl:intsched} 156 156 % ====================================================================== 157 157 % ====================================================================== … … 165 165 \end{figure} 166 166 167 This picture has several components, the two most important being the entry queue and the AS-stack. The entry queue is an (almost) FIFO list where threads waiting to enter are parked, while the acceptor/signaller (AS) stack is a FILO list used for threads that have been signalled or otherwise marked as running next.167 This picture has several components, the two most important being the entry-queue and the AS-stack. The entry-queue is an (almost) FIFO list where threads waiting to enter are parked, while the acceptor-signaler (AS) stack is a FILO list used for threads that have been signalled or otherwise marked as running next. 168 168 169 169 For \CFA, this picture does not have support for blocking multiple monitors on a single condition. To support \gls{bulk-acq} two changes to this picture are required. First, it is no longer helpful to attach the condition to \emph{a single} monitor. Secondly, the thread waiting on the condition has to be separated across multiple monitors, seen in figure \ref{fig:monitor_cfa}. … … 173 173 {\resizebox{0.8\textwidth}{!}{\input{int_monitor}}} 174 174 \end{center} 175 \caption{Illustration of \CFA Monitor}175 \caption{Illustration of \CFA monitor} 176 176 \label{fig:monitor_cfa} 177 177 \end{figure} 178 178 179 This picture and the proper entry and leave algorithms (see listing \ref{lst:entry2}) is the fundamental implementation of internal scheduling. Note that when a thread is moved from the condition to the AS-stack, it is conceptually split the thread into N pieces, where N is the number of monitors specified in the parameter list. The thread is woken up when all the pieces have popped from the AS-stacks and made active. In this picture, the threads are split into halves but this is only because there are two monitors. For a specific signal ling operation every monitor needs a piece of thread on its AS-stack.179 This picture and the proper entry and leave algorithms (see listing \ref{lst:entry2}) is the fundamental implementation of internal scheduling. Note that when a thread is moved from the condition to the AS-stack, it is conceptually split the thread into N pieces, where N is the number of monitors specified in the parameter list. The thread is woken up when all the pieces have popped from the AS-stacks and made active. In this picture, the threads are split into halves but this is only because there are two monitors. For a specific signaling operation every monitor needs a piece of thread on its AS-stack. 180 180 181 181 \begin{figure}[b] … … 210 210 \end{figure} 211 211 212 Some important things to notice about the exit routine. The solution discussed in \ref{intsched} can be seen in the exit routine of listing \ref{lst:entry2}. Basically, the solution boils down to having a separate data structure for the condition queue and the AS-stack, and unconditionally transferring ownership of the monitors but only unblocking the thread when the last monitor has transferred ownership. This solution is deadlock safe as well as preventing any potential barging. The data structure s used for the AS-stack are reused extensively for external scheduling, but in the case of internal scheduling, the data is allocated using variable-length arrays on the callstack of the \code{wait} and \code{signal_block} routines.212 Some important things to notice about the exit routine. The solution discussed in \ref{intsched} can be seen in the exit routine of listing \ref{lst:entry2}. Basically, the solution boils down to having a separate data structure for the condition queue and the AS-stack, and unconditionally transferring ownership of the monitors but only unblocking the thread when the last monitor has transferred ownership. This solution is deadlock safe as well as preventing any potential barging. The data structure used for the AS-stack are reused extensively for external scheduling, but in the case of internal scheduling, the data is allocated using variable-length arrays on the call-stack of the \code{wait} and \code{signal_block} routines. 213 213 214 214 \begin{figure}[H] … … 220 220 \end{figure} 221 221 222 Figure \ref{fig:structs} shows a high-level representation of these data structures. The main idea behind them is that, a thread cannot contain an arbitrary number of intrusive stacks for linking onto monitor. The \code{condition node} is the data structure that is queued onto a condition variable and, when signalled, the condition queue is popped and each \code{condition criterion} is moved to the AS-stack. Once all the criteria have been popped from their respective AS-stacks, the thread is wokenup, which is what is shown in listing \ref{lst:entry2}.223 224 % ====================================================================== 225 % ====================================================================== 226 \section{External Scheduling}222 Figure \ref{fig:structs} shows a high-level representation of these data-structures. The main idea behind them is that, a thread cannot contain an arbitrary number of intrusive stacks for linking onto monitor. The \code{condition node} is the data structure that is queued onto a condition variable and, when signaled, the condition queue is popped and each \code{condition criterion} are moved to the AS-stack. Once all the criterion have be popped from their respective AS-stacks, the thread is woken-up, which is what is shown in listing \ref{lst:entry2}. 223 224 % ====================================================================== 225 % ====================================================================== 226 \section{External scheduling} 227 227 % ====================================================================== 228 228 % ====================================================================== … … 232 232 \begin{itemize} 233 233 \item The queue of the monitor with the lowest address is no longer a true FIFO queue because threads can be moved to the front of the queue. These queues need to contain a set of monitors for each of the waiting threads. Therefore, another thread whose set contains the same lowest address monitor but different lower priority monitors may arrive first but enter the critical section after a thread with the correct pairing. 234 \item The queue of the lowest priority monitor is both required and potentially unused. Indeed, since it is not known at compile time which monitor is the monitor w hich hasthe lowest address, every monitor needs to have the correct queues even though it is possible that some queues go unused for the entire duration of the program, for example if a monitor is only used in a specific pair.234 \item The queue of the lowest priority monitor is both required and potentially unused. Indeed, since it is not known at compile time which monitor is the monitor with have the lowest address, every monitor needs to have the correct queues even though it is possible that some queues go unused for the entire duration of the program, for example if a monitor is only used in a specific pair. 235 235 \end{itemize} 236 236 Therefore, the following modifications need to be made to support external scheduling : … … 241 241 \end{itemize} 242 242 243 \subsection{External Scheduling - Destructors}244 Finally, to support the ordering inversion of destructors, the code generation needs to be modified to use a special entry routine. This routine is needed because of the storage requirements of the call order inversion. Indeed, when waiting for the destructors, storage is need ed for the waiting context and the lifetime of said storage needs to outlive the waiting operation it is needed for. For regular \code{waitfor} statements, the callstack of the routine itself matches this requirement but it is no longer the case when waiting for the destructor since it is pushed on to the AS-stack for later. The waitfor semantics can then be adjusted correspondingly, as seen in listing \ref{lst:entry-dtor}243 \subsection{External scheduling - destructors} 244 Finally, to support the ordering inversion of destructors, the code generation needs to be modified to use a special entry routine. This routine is needed because of the storage requirements of the call order inversion. Indeed, when waiting for the destructors, storage is need for the waiting context and the lifetime of said storage needs to outlive the waiting operation it is needed for. For regular \code{waitfor} statements, the call-stack of the routine itself matches this requirement but it is no longer the case when waiting for the destructor since it is pushed on to the AS-stack for later. The waitfor semantics can then be adjusted correspondingly, as seen in listing \ref{lst:entry-dtor} 245 245 246 246 \begin{figure} … … 253 253 continue 254 254 elif matches waitfor mask 255 push criteri ato AS-stack255 push criterions to AS-stack 256 256 continue 257 257 else -
doc/proposals/concurrency/text/parallelism.tex
rc13e8dc8 r9c35431 10 10 11 11 \section{Paradigms} 12 \subsection{User- Level Threads}13 A direct improvement on the \gls{kthread} approach is to use \glspl{uthread}. These threads offer most of the same features that the operating system already provide s but can be used on a much larger scale. This approach is the most powerful solution as it allows all the features of multithreading, while removing several of the more expensive costs of kernel threads. The downside is that almost none of the low-level threading problems are hidden; users still have to think about data races, deadlocks and synchronization issues. These issues can be somewhat alleviated by a concurrency toolkit with strong guarantees but the parallelism toolkit offers very little to reduce complexity in itself.12 \subsection{User-level threads} 13 A direct improvement on the \gls{kthread} approach is to use \glspl{uthread}. These threads offer most of the same features that the operating system already provide but can be used on a much larger scale. This approach is the most powerful solution as it allows all the features of multi-threading, while removing several of the more expensive costs of kernel threads. The down side is that almost none of the low-level threading problems are hidden; users still have to think about data races, deadlocks and synchronization issues. These issues can be somewhat alleviated by a concurrency toolkit with strong guarantees but the parallelism toolkit offers very little to reduce complexity in itself. 14 14 15 15 Examples of languages that support \glspl{uthread} are Erlang~\cite{Erlang} and \uC~\cite{uC++book}. 16 16 17 \subsection{Fibers : User-Level Threads Without Preemption} \label{fibers}18 A popular variant of \glspl{uthread} is what is often referred to as \glspl{fiber}. However, \glspl{fiber} do not present meaningful semantic differences with \glspl{uthread}. The significant difference between \glspl{uthread} and \glspl{fiber} is the lack of \gls{preemption} in the latter. Advocates of \glspl{fiber} list their high performance and ease of implementation as majorstrengths but the performance difference between \glspl{uthread} and \glspl{fiber} is controversial, and the ease of implementation, while true, is a weak argument in the context of language design. Therefore this proposal largely ignores fibers.17 \subsection{Fibers : user-level threads without preemption} \label{fibers} 18 A popular variant of \glspl{uthread} is what is often referred to as \glspl{fiber}. However, \glspl{fiber} do not present meaningful semantical differences with \glspl{uthread}. The significant difference between \glspl{uthread} and \glspl{fiber} is the lack of \gls{preemption} in the latter. Advocates of \glspl{fiber} list their high performance and ease of implementation as majors strengths but the performance difference between \glspl{uthread} and \glspl{fiber} is controversial, and the ease of implementation, while true, is a weak argument in the context of language design. Therefore this proposal largely ignores fibers. 19 19 20 20 An example of a language that uses fibers is Go~\cite{Go} 21 21 22 \subsection{Jobs and Thread Pools}23 An approach on the opposite end of the spectrum is to base parallelism on \glspl{pool}. Indeed, \glspl{pool} offer limited flexibility but at the benefit of a simpler user interface. In \gls{pool} based systems, users express parallelism as units of work, called jobs, and a dependency graph (either explicit or implicit) that tie s them together. This approach means users need not worry about concurrency but significantly limit the interaction that can occur among jobs. Indeed, any \gls{job} that blocks also block the underlying worker, which effectively means the CPU utilization, and therefore throughput, suffers noticeably. It can be argued that a solution to this problem is to use more workers than available cores. However, unless the number of jobs and the number of workers are comparable, having a significant numberof blocked jobs always results in idles cores.22 \subsection{Jobs and thread pools} 23 An approach on the opposite end of the spectrum is to base parallelism on \glspl{pool}. Indeed, \glspl{pool} offer limited flexibility but at the benefit of a simpler user interface. In \gls{pool} based systems, users express parallelism as units of work, called jobs, and a dependency graph (either explicit or implicit) that tie them together. This approach means users need not worry about concurrency but significantly limit the interaction that can occur among jobs. Indeed, any \gls{job} that blocks also blocks the underlying worker, which effectively means the CPU utilization, and therefore throughput, suffers noticeably. It can be argued that a solution to this problem is to use more workers than available cores. However, unless the number of jobs and the number of workers are comparable, having a significant amount of blocked jobs always results in idles cores. 24 24 25 25 The gold standard of this implementation is Intel's TBB library~\cite{TBB}. 26 26 27 \subsection{Paradigm Performance}28 While the choice between the three paradigms listed above may have significant performance implication, it is difficult to pin down the performance implications of choosing a model at the language level. Indeed, in many situations one of these paradigms may show better performance but it all strongly depends on the workload. Having a large amount of mostly independent units of work to execute almost guarantees that the \gls{pool}-based system has the best performance thanks to the lower memory overhead (i.e., no thread stack per job). However, interactions among jobs can easily exacerbate contention. User-level threads allow fine-grain context switching, which results in better resource utilization, but a context switch is more expensive and the extra control means users need to tweak more variables to get the desired performance. Finally, if the units of uninterrupted work are large enough the paradigm choice is largely amortized by the actual work done.27 \subsection{Paradigm performance} 28 While the choice between the three paradigms listed above may have significant performance implication, it is difficult to pin-down the performance implications of choosing a model at the language level. Indeed, in many situations one of these paradigms may show better performance but it all strongly depends on the workload. Having a large amount of mostly independent units of work to execute almost guarantees that the \gls{pool} based system has the best performance thanks to the lower memory overhead (i.e., no thread stack per job). However, interactions among jobs can easily exacerbate contention. User-level threads allow fine-grain context switching, which results in better resource utilization, but a context switch is more expensive and the extra control means users need to tweak more variables to get the desired performance. Finally, if the units of uninterrupted work are large enough the paradigm choice is largely amortized by the actual work done. 29 29 30 30 \section{The \protect\CFA\ Kernel : Processors, Clusters and Threads}\label{kernel} … … 33 33 \Glspl{cfacluster} have not been fully implemented in the context of this thesis, currently \CFA only supports one \gls{cfacluster}, the initial one. 34 34 35 \subsection{Future Work: Machine Setup}\label{machine}35 \subsection{Future Work: Machine setup}\label{machine} 36 36 While this was not done in the context of this thesis, another important aspect of clusters is affinity. While many common desktop and laptop PCs have homogeneous CPUs, other devices often have more heterogeneous setups. For example, a system using \acrshort{numa} configurations may benefit from users being able to tie clusters and\/or kernel threads to certain CPU cores. OS support for CPU affinity is now common~\cite{affinityLinux, affinityWindows, affinityFreebsd, affinityNetbsd, affinityMacosx} which means it is both possible and desirable for \CFA to offer an abstraction mechanism for portable CPU affinity. 37 37 38 38 \subsection{Paradigms}\label{cfaparadigms} 39 Given these building blocks, it is possible to reproduce all three of the popular paradigms. Indeed, \glspl{uthread} is the default paradigm in \CFA. However, disabling \gls{preemption} on the \gls{cfacluster} means \glspl{cfathread} effectively become \glspl{fiber}. Since several \glspl{cfacluster} with different scheduling policy can coexist in the same application, this allows \glspl{fiber} and \glspl{uthread} to coexist in the runtime of an application. Finally, it is possible to build executors for thread pools from \glspl{uthread} or \glspl{fiber}, which includes specialize djobs like actors~\cite{Actors}.39 Given these building blocks, it is possible to reproduce all three of the popular paradigms. Indeed, \glspl{uthread} is the default paradigm in \CFA. However, disabling \gls{preemption} on the \gls{cfacluster} means \glspl{cfathread} effectively become \glspl{fiber}. Since several \glspl{cfacluster} with different scheduling policy can coexist in the same application, this allows \glspl{fiber} and \glspl{uthread} to coexist in the runtime of an application. Finally, it is possible to build executors for thread pools from \glspl{uthread} or \glspl{fiber}, which includes specialize jobs like actors~\cite{Actors}. -
doc/proposals/concurrency/text/results.tex
rc13e8dc8 r9c35431 1 1 % ====================================================================== 2 2 % ====================================================================== 3 \chapter{Performance Results} \label{results}3 \chapter{Performance results} \label{results} 4 4 % ====================================================================== 5 5 % ====================================================================== 6 \section{Machine Setup}7 Table \ref{tab:machine} shows the characteristics of the machine used to run the benchmarks. All tests w ere made on this machine.6 \section{Machine setup} 7 Table \ref{tab:machine} shows the characteristics of the machine used to run the benchmarks. All tests where made on this machine. 8 8 \begin{table}[H] 9 9 \begin{center} … … 37 37 \end{table} 38 38 39 \section{Micro Benchmarks}39 \section{Micro benchmarks} 40 40 All benchmarks are run using the same harness to produce the results, seen as the \code{BENCH()} macro in the following examples. This macro uses the following logic to benchmark the code : 41 41 \begin{pseudo} … … 46 46 result = (after - before) / N; 47 47 \end{pseudo} 48 The method used to get time is \code{clock_gettime(CLOCK_THREAD_CPUTIME_ID);}. Each benchmark is using many iterations of a simple call to measure the cost of the call. The specific number of iteration sdepends on the specific benchmark.49 50 \subsection{Context- Switching}51 The first interesting benchmark is to measure how long context-switches take. The simplest approach to do this is to yield on a thread, which executes a 2-step context switch. In order to make the comparison fair, coroutines also execute a 2-step context-switch (\gls{uthread} to \gls{kthread} then \gls{kthread} to \gls{uthread}), which is a resume/suspend cycle instead of a yield. Listing \ref{lst:ctx-switch} shows the code for coroutines and threads w ith the results in table \ref{tab:ctx-switch}. All omitted tests are functionally identical to one of these tests.48 The method used to get time is \code{clock_gettime(CLOCK_THREAD_CPUTIME_ID);}. Each benchmark is using many iterations of a simple call to measure the cost of the call. The specific number of iteration depends on the specific benchmark. 49 50 \subsection{Context-switching} 51 The first interesting benchmark is to measure how long context-switches take. The simplest approach to do this is to yield on a thread, which executes a 2-step context switch. In order to make the comparison fair, coroutines also execute a 2-step context-switch (\gls{uthread} to \gls{kthread} then \gls{kthread} to \gls{uthread}), which is a resume/suspend cycle instead of a yield. Listing \ref{lst:ctx-switch} shows the code for coroutines and threads whith the results in table \ref{tab:ctx-switch}. All omitted tests are functionally identical to one of these tests. 52 52 \begin{figure} 53 53 \begin{multicols}{2} … … 114 114 \end{table} 115 115 116 \subsection{Mutual- Exclusion}117 The next interesting benchmark is to measure the overhead to enter/leave a critical-section. For monitors, the simplest approach is to measure how long it takes to enter and leave a monitor routine. Listing \ref{lst:mutex} shows the code for \CFA. To put the results in context, the cost of entering a non-inline function and the cost of acquiring and releasing a pthread mutex lock isalso measured. The results can be shown in table \ref{tab:mutex}.116 \subsection{Mutual-exclusion} 117 The next interesting benchmark is to measure the overhead to enter/leave a critical-section. For monitors, the simplest approach is to measure how long it takes to enter and leave a monitor routine. Listing \ref{lst:mutex} shows the code for \CFA. To put the results in context, the cost of entering a non-inline function and the cost of acquiring and releasing a pthread mutex lock are also measured. The results can be shown in table \ref{tab:mutex}. 118 118 119 119 \begin{figure} … … 156 156 \end{table} 157 157 158 \subsection{Internal Scheduling}158 \subsection{Internal scheduling} 159 159 The internal-scheduling benchmark measures the cost of waiting on and signalling a condition variable. Listing \ref{lst:int-sched} shows the code for \CFA, with results table \ref{tab:int-sched}. As with all other benchmarks, all omitted tests are functionally identical to one of these tests. 160 160 … … 211 211 \end{table} 212 212 213 \subsection{External Scheduling}213 \subsection{External scheduling} 214 214 The Internal scheduling benchmark measures the cost of the \code{waitfor} statement (\code{_Accept} in \uC). Listing \ref{lst:ext-sched} shows the code for \CFA, with results in table \ref{tab:ext-sched}. As with all other benchmarks, all omitted tests are functionally identical to one of these tests. 215 215 … … 264 264 \end{table} 265 265 266 \subsection{Object Creation}267 Finally, the last benchmark measur es the cost of creation for concurrent objects. Listing \ref{lst:creation} shows the code for pthreads and \CFA threads, with results shown in table \ref{tab:creation}. As with all other benchmarks, all omitted tests are functionally identical to one of these tests. The only note here is that the callstacks of \CFA coroutines are lazily created, therefore without priming the coroutine, the creation cost is very low.266 \subsection{Object creation} 267 Finally, the last benchmark measurs the cost of creation for concurrent objects. Listing \ref{lst:creation} shows the code for pthreads and \CFA threads, with results shown in table \ref{tab:creation}. As with all other benchmarks, all omitted tests are functionally identical to one of these tests. The only note here is that the call-stacks of \CFA coroutines are lazily created, therefore without priming the coroutine, the creation cost is very low. 268 268 269 269 \begin{figure} … … 327 327 \end{tabular} 328 328 \end{center} 329 \caption{Creation comparison. All numbers are in nanoseconds(\si{\nano\second}) .}329 \caption{Creation comparison. All numbers are in nanoseconds(\si{\nano\second})} 330 330 \label{tab:creation} 331 331 \end{table} -
doc/proposals/concurrency/text/together.tex
rc13e8dc8 r9c35431 1 1 % ====================================================================== 2 2 % ====================================================================== 3 \chapter{Putting It All Together}3 \chapter{Putting it all together} 4 4 % ====================================================================== 5 5 % ====================================================================== 6 6 7 7 8 \section{Threads As Monitors}8 \section{Threads as monitors} 9 9 As it was subtly alluded in section \ref{threads}, \code{thread}s in \CFA are in fact monitors, which means that all monitor features are available when using threads. For example, here is a very simple two thread pipeline that could be used for a simulator of a game engine : 10 10 \begin{figure}[H] -
doc/proposals/concurrency/version
rc13e8dc8 r9c35431 1 0.11.2 991 0.11.280 -
src/CodeGen/CodeGenerator.cc
rc13e8dc8 r9c35431 1012 1012 } 1013 1013 1014 void CodeGenerator::postvisit( WithStmt * with ) {1015 if ( ! genC ) {1016 output << "with ( ";1017 genCommaList( with->exprs.begin(), with->exprs.end() );1018 output << " ) ";1019 }1020 with->stmt->accept( *visitor );1021 }1022 1014 1023 1015 void CodeGenerator::postvisit( WhileStmt * whileStmt ) { -
src/CodeGen/CodeGenerator.h
rc13e8dc8 r9c35431 102 102 void postvisit( CatchStmt * ); 103 103 void postvisit( WaitForStmt * ); 104 void postvisit( WithStmt * );105 104 void postvisit( WhileStmt * ); 106 105 void postvisit( ForStmt * ); -
src/CodeGen/FixNames.cc
rc13e8dc8 r9c35431 19 19 #include <string> // for string, operator!=, operator== 20 20 21 #include "Common/PassVisitor.h"22 21 #include "Common/SemanticError.h" // for SemanticError 23 22 #include "FixMain.h" // for FixMain … … 33 32 34 33 namespace CodeGen { 35 class FixNames : public WithGuards{34 class FixNames : public Visitor { 36 35 public: 37 v oid postvisit( ObjectDecl *objectDecl );38 v oid postvisit( FunctionDecl *functionDecl );36 virtual void visit( ObjectDecl *objectDecl ); 37 virtual void visit( FunctionDecl *functionDecl ); 39 38 40 v oid previsit( CompoundStmt *compoundStmt );39 virtual void visit( CompoundStmt *compoundStmt ); 41 40 private: 42 41 int scopeLevel = 1; … … 94 93 } 95 94 96 void fixNames( std::list< Declaration* > &translationUnit ) {97 PassVisitor<FixNames>fixer;95 void fixNames( std::list< Declaration* > translationUnit ) { 96 FixNames fixer; 98 97 acceptAll( translationUnit, fixer ); 99 98 } 100 99 101 void FixNames::fixDWT( DeclarationWithType * dwt ) {100 void FixNames::fixDWT( DeclarationWithType *dwt ) { 102 101 if ( dwt->get_name() != "" ) { 103 102 if ( LinkageSpec::isMangled( dwt->get_linkage() ) ) { … … 108 107 } 109 108 110 void FixNames::postvisit( ObjectDecl * objectDecl ) { 109 void FixNames::visit( ObjectDecl *objectDecl ) { 110 Visitor::visit( objectDecl ); 111 111 fixDWT( objectDecl ); 112 112 } 113 113 114 void FixNames::postvisit( FunctionDecl * functionDecl ) { 114 void FixNames::visit( FunctionDecl *functionDecl ) { 115 Visitor::visit( functionDecl ); 115 116 fixDWT( functionDecl ); 116 117 … … 120 121 throw SemanticError("Main expected to have 0, 2 or 3 arguments\n", functionDecl); 121 122 } 122 functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( n ew ConstantExpr( Constant::from_int( 0 ) ) ) );123 functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new ConstantExpr( Constant::from_int( 0 ) ) ) ); 123 124 CodeGen::FixMain::registerMain( functionDecl ); 124 125 } 125 126 } 126 127 127 void FixNames:: previsit( CompoundStmt *) {128 void FixNames::visit( CompoundStmt *compoundStmt ) { 128 129 scopeLevel++; 129 GuardAction( [this](){ scopeLevel--; } ); 130 Visitor::visit( compoundStmt ); 131 scopeLevel--; 130 132 } 131 133 } // namespace CodeGen -
src/CodeGen/FixNames.h
rc13e8dc8 r9c35431 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixNames.h -- 7 // FixNames.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 22 22 namespace CodeGen { 23 23 /// mangles object and function names 24 void fixNames( std::list< Declaration* > &translationUnit );24 void fixNames( std::list< Declaration* > translationUnit ); 25 25 } // namespace CodeGen 26 26 -
src/Common/PassVisitor.h
rc13e8dc8 r9c35431 81 81 virtual void visit( FinallyStmt * finallyStmt ) override final; 82 82 virtual void visit( WaitForStmt * waitforStmt ) override final; 83 virtual void visit( WithStmt * withStmt ) override final;84 83 virtual void visit( NullStmt * nullStmt ) override final; 85 84 virtual void visit( DeclStmt * declStmt ) override final; … … 173 172 virtual Statement * mutate( FinallyStmt * finallyStmt ) override final; 174 173 virtual Statement * mutate( WaitForStmt * waitforStmt ) override final; 175 virtual Statement * mutate( WithStmt * withStmt ) override final;176 174 virtual NullStmt * mutate( NullStmt * nullStmt ) override final; 177 175 virtual Statement * mutate( DeclStmt * declStmt ) override final; … … 298 296 void indexerAddUnionFwd ( UnionDecl * node ) { indexer_impl_addUnionFwd ( pass, 0, node ); } 299 297 void indexerAddTrait ( TraitDecl * node ) { indexer_impl_addTrait ( pass, 0, node ); } 300 void indexerAddWith ( WithStmt * node ) { indexer_impl_addWith ( pass, 0, node ); }301 302 298 303 299 template< typename TreeType, typename VisitorType > -
src/Common/PassVisitor.impl.h
rc13e8dc8 r9c35431 55 55 it, 56 56 [](Declaration * decl) -> auto { 57 return new DeclStmt( decl );57 return new DeclStmt( noLabels, decl ); 58 58 } 59 59 ); … … 251 251 || ( empty( beforeDecls ) && empty( afterDecls )) ); 252 252 253 CompoundStmt *compound = new CompoundStmt( );253 CompoundStmt *compound = new CompoundStmt( noLabels ); 254 254 if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); } 255 255 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } … … 400 400 { 401 401 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 402 // implicit add __func__ identifier as specified in the C manual 6.4.2.2403 static ObjectDecl func(404 "__func__", noStorageClasses, LinkageSpec::C, nullptr,405 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),406 nullptr407 );408 indexerAddId( &func );409 402 maybeAccept_impl( node->type, *this ); 410 403 maybeAccept_impl( node->statements, *this ); … … 425 418 { 426 419 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 427 // implicit add __func__ identifier as specified in the C manual 6.4.2.2428 static ObjectDecl func(429 "__func__", noStorageClasses, LinkageSpec::C, nullptr,430 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),431 nullptr432 );433 indexerAddId( &func );434 420 maybeMutate_impl( node->type, *this ); 435 421 maybeMutate_impl( node->statements, *this ); … … 985 971 } 986 972 987 988 989 //--------------------------------------------------------------------------990 // NullStmt991 template< typename pass_type >992 void PassVisitor< pass_type >::visit( WithStmt * node ) {993 VISIT_START( node );994 maybeAccept_impl( node->exprs, *this );995 {996 // catch statements introduce a level of scope (for the caught exception)997 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );998 indexerAddWith( node );999 maybeAccept_impl( node->stmt, *this );1000 }1001 VISIT_END( node );1002 }1003 1004 template< typename pass_type >1005 Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) {1006 MUTATE_START( node );1007 maybeMutate_impl( node->exprs, *this );1008 {1009 // catch statements introduce a level of scope (for the caught exception)1010 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );1011 indexerAddWith( node );1012 maybeMutate_impl( node->stmt, *this );1013 }1014 MUTATE_END( Statement, node );1015 }1016 1017 973 //-------------------------------------------------------------------------- 1018 974 // NullStmt -
src/Common/PassVisitor.proto.h
rc13e8dc8 r9c35431 208 208 INDEXER_FUNC( addUnion , UnionDecl * ); 209 209 INDEXER_FUNC( addTrait , TraitDecl * ); 210 INDEXER_FUNC( addWith , WithStmt * );211 210 212 211 -
src/Concurrency/Keywords.cc
rc13e8dc8 r9c35431 38 38 39 39 namespace Concurrency { 40 41 namespace { 42 const std::list<Label> noLabels; 43 const std::list< Attribute * > noAttributes; 44 Type::StorageClasses noStorage; 45 Type::Qualifiers noQualifiers; 46 } 47 40 48 //============================================================================================= 41 49 // Pass declarations … … 288 296 ObjectDecl * this_decl = new ObjectDecl( 289 297 "this", 290 noStorage Classes,298 noStorage, 291 299 LinkageSpec::Cforall, 292 300 nullptr, … … 305 313 new ObjectDecl( 306 314 "ret", 307 noStorage Classes,315 noStorage, 308 316 LinkageSpec::Cforall, 309 317 nullptr, … … 338 346 main_decl = new FunctionDecl( 339 347 "main", 340 noStorage Classes,348 noStorage, 341 349 LinkageSpec::Cforall, 342 350 main_type, … … 355 363 ObjectDecl * field = new ObjectDecl( 356 364 field_name, 357 noStorage Classes,365 noStorage, 358 366 LinkageSpec::Cforall, 359 367 nullptr, … … 371 379 372 380 void ConcurrentSueKeyword::addRoutines( ObjectDecl * field, FunctionDecl * func ) { 373 CompoundStmt * statement = new CompoundStmt( );381 CompoundStmt * statement = new CompoundStmt( noLabels ); 374 382 statement->push_back( 375 383 new ReturnStmt( 384 noLabels, 376 385 new AddressExpr( 377 386 new MemberExpr( … … 479 488 ObjectDecl * monitors = new ObjectDecl( 480 489 "__monitor", 481 noStorage Classes,490 noStorage, 482 491 LinkageSpec::Cforall, 483 492 nullptr, … … 500 509 // monitor_guard_t __guard = { __monitors, #, func }; 501 510 body->push_front( 502 new DeclStmt( n ew ObjectDecl(511 new DeclStmt( noLabels, new ObjectDecl( 503 512 "__guard", 504 noStorage Classes,513 noStorage, 505 514 LinkageSpec::Cforall, 506 515 nullptr, … … 521 530 522 531 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) }; 523 body->push_front( new DeclStmt( monitors) );532 body->push_front( new DeclStmt( noLabels, monitors) ); 524 533 } 525 534 … … 527 536 ObjectDecl * monitors = new ObjectDecl( 528 537 "__monitors", 529 noStorage Classes,538 noStorage, 530 539 LinkageSpec::Cforall, 531 540 nullptr, … … 560 569 // monitor_guard_t __guard = { __monitors, #, func }; 561 570 body->push_front( 562 new DeclStmt( n ew ObjectDecl(571 new DeclStmt( noLabels, new ObjectDecl( 563 572 "__guard", 564 noStorage Classes,573 noStorage, 565 574 LinkageSpec::Cforall, 566 575 nullptr, … … 582 591 583 592 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) }; 584 body->push_front( new DeclStmt( monitors) );593 body->push_front( new DeclStmt( noLabels, monitors) ); 585 594 } 586 595 … … 622 631 stmt->push_back( 623 632 new ExprStmt( 633 noLabels, 624 634 new UntypedExpr( 625 635 new NameExpr( "__thrd_start" ), -
src/Concurrency/Waitfor.cc
rc13e8dc8 r9c35431 100 100 101 101 namespace Concurrency { 102 103 namespace { 104 const std::list<Label> noLabels; 105 const std::list< Attribute * > noAttributes; 106 Type::StorageClasses noStorage; 107 Type::Qualifiers noQualifiers; 108 } 109 102 110 //============================================================================================= 103 111 // Pass declarations … … 195 203 ResolvExpr::findVoidExpression( expr, indexer ); 196 204 197 return new ExprStmt( expr );205 return new ExprStmt( noLabels, expr ); 198 206 } 199 207 … … 251 259 if( !decl_monitor || !decl_acceptable || !decl_mask ) throw SemanticError( "waitfor keyword requires monitors to be in scope, add #include <monitor>", waitfor ); 252 260 253 CompoundStmt * stmt = new CompoundStmt( );261 CompoundStmt * stmt = new CompoundStmt( noLabels ); 254 262 255 263 ObjectDecl * acceptables = declare( waitfor->clauses.size(), stmt ); … … 273 281 ); 274 282 275 CompoundStmt * compound = new CompoundStmt( );283 CompoundStmt * compound = new CompoundStmt( noLabels ); 276 284 stmt->push_back( new IfStmt( 285 noLabels, 277 286 safeCond( new VariableExpr( flag ) ), 278 287 compound, … … 304 313 ); 305 314 306 stmt->push_back( new DeclStmt( acceptables) );315 stmt->push_back( new DeclStmt( noLabels, acceptables) ); 307 316 308 317 Expression * set = new UntypedExpr( … … 317 326 ResolvExpr::findVoidExpression( set, indexer ); 318 327 319 stmt->push_back( new ExprStmt( set ) );328 stmt->push_back( new ExprStmt( noLabels, set ) ); 320 329 321 330 return acceptables; … … 332 341 ); 333 342 334 stmt->push_back( new DeclStmt( flag) );343 stmt->push_back( new DeclStmt( noLabels, flag) ); 335 344 336 345 return flag; … … 348 357 ResolvExpr::findVoidExpression( expr, indexer ); 349 358 350 return new ExprStmt( expr );359 return new ExprStmt( noLabels, expr ); 351 360 } 352 361 … … 390 399 ); 391 400 392 stmt->push_back( new DeclStmt( mon) );401 stmt->push_back( new DeclStmt( noLabels, mon) ); 393 402 394 403 return mon; … … 402 411 403 412 stmt->push_back( new IfStmt( 413 noLabels, 404 414 safeCond( clause.condition ), 405 415 new CompoundStmt({ … … 437 447 ); 438 448 439 stmt->push_back( new DeclStmt( timeout ) );449 stmt->push_back( new DeclStmt( noLabels, timeout ) ); 440 450 441 451 if( time ) { 442 452 stmt->push_back( new IfStmt( 453 noLabels, 443 454 safeCond( time_cond ), 444 455 new CompoundStmt({ 445 456 new ExprStmt( 457 noLabels, 446 458 makeOpAssign( 447 459 new VariableExpr( timeout ), … … 459 471 if( has_else ) { 460 472 stmt->push_back( new IfStmt( 473 noLabels, 461 474 safeCond( else_cond ), 462 475 new CompoundStmt({ 463 476 new ExprStmt( 477 noLabels, 464 478 makeOpAssign( 465 479 new VariableExpr( timeout ), … … 497 511 ); 498 512 499 stmt->push_back( new DeclStmt( index ) );513 stmt->push_back( new DeclStmt( noLabels, index ) ); 500 514 501 515 ObjectDecl * mask = ObjectDecl::newObject( … … 512 526 ); 513 527 514 stmt->push_back( new DeclStmt( mask ) );528 stmt->push_back( new DeclStmt( noLabels, mask ) ); 515 529 516 530 stmt->push_back( new ExprStmt( 531 noLabels, 517 532 new ApplicationExpr( 518 533 VariableExpr::functionPointer( decl_waitfor ), … … 542 557 ) { 543 558 SwitchStmt * swtch = new SwitchStmt( 559 noLabels, 544 560 result, 545 561 std::list<Statement *>() … … 550 566 swtch->statements.push_back( 551 567 new CaseStmt( 568 noLabels, 552 569 new ConstantExpr( Constant::from_ulong( i++ ) ), 553 570 { 554 571 clause.statement, 555 572 new BranchStmt( 573 noLabels, 556 574 "", 557 575 BranchStmt::Break … … 565 583 swtch->statements.push_back( 566 584 new CaseStmt( 585 noLabels, 567 586 new ConstantExpr( Constant::from_int( -2 ) ), 568 587 { 569 588 waitfor->timeout.statement, 570 589 new BranchStmt( 590 noLabels, 571 591 "", 572 592 BranchStmt::Break … … 580 600 swtch->statements.push_back( 581 601 new CaseStmt( 602 noLabels, 582 603 new ConstantExpr( Constant::from_int( -1 ) ), 583 604 { 584 605 waitfor->orelse.statement, 585 606 new BranchStmt( 607 noLabels, 586 608 "", 587 609 BranchStmt::Break -
src/ControlStruct/ExceptTranslate.cc
rc13e8dc8 r9c35431 30 30 #include "SynTree/Expression.h" // for UntypedExpr, ConstantExpr, Name... 31 31 #include "SynTree/Initializer.h" // for SingleInit, ListInit 32 #include "SynTree/Label.h" // for Label 32 #include "SynTree/Label.h" // for Label, noLabels 33 33 #include "SynTree/Mutator.h" // for mutateAll 34 34 #include "SynTree/Statement.h" // for CompoundStmt, CatchStmt, ThrowStmt … … 57 57 58 58 void appendDeclStmt( CompoundStmt * block, Declaration * item ) { 59 block->push_back(new DeclStmt( item));59 block->push_back(new DeclStmt(noLabels, item)); 60 60 } 61 61 … … 205 205 throwStmt->set_expr( nullptr ); 206 206 delete throwStmt; 207 return new ExprStmt( call );207 return new ExprStmt( noLabels, call ); 208 208 } 209 209 … … 211 211 ThrowStmt *throwStmt ) { 212 212 // __throw_terminate( `throwStmt->get_name()` ); } 213 return create_given_throw( "__cfa abi_ehm__throw_terminate", throwStmt );213 return create_given_throw( "__cfaehm__throw_terminate", throwStmt ); 214 214 } 215 215 … … 220 220 assert( handler_except_decl ); 221 221 222 CompoundStmt * result = new CompoundStmt(); 223 result->labels = throwStmt->labels; 224 result->push_back( new ExprStmt( UntypedExpr::createAssign( 222 CompoundStmt * result = new CompoundStmt( throwStmt->get_labels() ); 223 result->push_back( new ExprStmt( noLabels, UntypedExpr::createAssign( 225 224 nameOf( handler_except_decl ), 226 225 new ConstantExpr( Constant::null( … … 232 231 ) ) ); 233 232 result->push_back( new ExprStmt( 234 new UntypedExpr( new NameExpr( "__cfaabi_ehm__rethrow_terminate" ) ) 233 noLabels, 234 new UntypedExpr( new NameExpr( "__cfaehm__rethrow_terminate" ) ) 235 235 ) ); 236 236 delete throwStmt; … … 241 241 ThrowStmt *throwStmt ) { 242 242 // __throw_resume( `throwStmt->get_name` ); 243 return create_given_throw( "__cfa abi_ehm__throw_resume", throwStmt );243 return create_given_throw( "__cfaehm__throw_resume", throwStmt ); 244 244 } 245 245 … … 248 248 // return false; 249 249 Statement * result = new ReturnStmt( 250 throwStmt->get_labels(), 250 251 new ConstantExpr( Constant::from_bool( false ) ) 251 252 ); 252 result->labels = throwStmt->labels;253 253 delete throwStmt; 254 254 return result; … … 291 291 // } 292 292 // return; 293 CompoundStmt * block = new CompoundStmt( );293 CompoundStmt * block = new CompoundStmt( noLabels ); 294 294 295 295 // Just copy the exception value. (Post Validation) … … 304 304 ) }) 305 305 ); 306 block->push_back( new DeclStmt( local_except ) );306 block->push_back( new DeclStmt( noLabels, local_except ) ); 307 307 308 308 // Add the cleanup attribute. 309 309 local_except->get_attributes().push_back( new Attribute( 310 310 "cleanup", 311 { new NameExpr( "__cfa abi_ehm__cleanup_terminate" ) }311 { new NameExpr( "__cfaehm__cleanup_terminate" ) } 312 312 ) ); 313 313 … … 324 324 325 325 std::list<Statement *> caseBody 326 { block, new ReturnStmt( n ullptr ) };326 { block, new ReturnStmt( noLabels, nullptr ) }; 327 327 handler_wrappers.push_back( new CaseStmt( 328 noLabels, 328 329 new ConstantExpr( Constant::from_int( index ) ), 329 330 caseBody … … 339 340 340 341 SwitchStmt * handler_lookup = new SwitchStmt( 342 noLabels, 341 343 nameOf( index_obj ), 342 344 stmt_handlers 343 345 ); 344 CompoundStmt * body = new CompoundStmt( );346 CompoundStmt * body = new CompoundStmt( noLabels ); 345 347 body->push_back( handler_lookup ); 346 348 … … 361 363 // } 362 364 363 CompoundStmt * block = new CompoundStmt( );365 CompoundStmt * block = new CompoundStmt( noLabels ); 364 366 365 367 // Local Declaration … … 367 369 dynamic_cast<ObjectDecl *>( modded_handler->get_decl() ); 368 370 assert( local_except ); 369 block->push_back( new DeclStmt( local_except ) );371 block->push_back( new DeclStmt( noLabels, local_except ) ); 370 372 371 373 // Check for type match. … … 379 381 } 380 382 // Construct the match condition. 381 block->push_back( new IfStmt( 383 block->push_back( new IfStmt( noLabels, 382 384 cond, modded_handler->get_body(), nullptr ) ); 383 385 … … 395 397 // } 396 398 397 CompoundStmt * body = new CompoundStmt( );399 CompoundStmt * body = new CompoundStmt( noLabels ); 398 400 399 401 FunctionType * func_type = match_func_t.clone(); … … 411 413 412 414 // Create new body. 413 handler->set_body( new ReturnStmt( 415 handler->set_body( new ReturnStmt( noLabels, 414 416 new ConstantExpr( Constant::from_int( index ) ) ) ); 415 417 … … 419 421 } 420 422 421 body->push_back( new ReturnStmt( 423 body->push_back( new ReturnStmt( noLabels, 422 424 new ConstantExpr( Constant::from_int( 0 ) ) ) ); 423 425 … … 430 432 FunctionDecl * terminate_catch, 431 433 FunctionDecl * terminate_match ) { 432 // { __cfa abi_ehm__try_terminate(`try`, `catch`, `match`); }434 // { __cfaehm__try_terminate(`try`, `catch`, `match`); } 433 435 434 436 UntypedExpr * caller = new UntypedExpr( new NameExpr( 435 "__cfa abi_ehm__try_terminate" ) );437 "__cfaehm__try_terminate" ) ); 436 438 std::list<Expression *>& args = caller->get_args(); 437 439 args.push_back( nameOf( try_wrapper ) ); … … 439 441 args.push_back( nameOf( terminate_match ) ); 440 442 441 CompoundStmt * callStmt = new CompoundStmt( );442 callStmt->push_back( new ExprStmt( caller ) );443 CompoundStmt * callStmt = new CompoundStmt( noLabels ); 444 callStmt->push_back( new ExprStmt( noLabels, caller ) ); 443 445 return callStmt; 444 446 } … … 449 451 // HANDLER WRAPPERS { `hander->body`; return true; } 450 452 // } 451 CompoundStmt * body = new CompoundStmt( );453 CompoundStmt * body = new CompoundStmt( noLabels ); 452 454 453 455 FunctionType * func_type = handle_func_t.clone(); … … 462 464 dynamic_cast<CompoundStmt*>( handler->get_body() ); 463 465 if ( ! handling_code ) { 464 handling_code = new CompoundStmt( );466 handling_code = new CompoundStmt( noLabels ); 465 467 handling_code->push_back( handler->get_body() ); 466 468 } 467 handling_code->push_back( new ReturnStmt( 469 handling_code->push_back( new ReturnStmt( noLabels, 468 470 new ConstantExpr( Constant::from_bool( true ) ) ) ); 469 471 handler->set_body( handling_code ); … … 474 476 } 475 477 476 body->push_back( new ReturnStmt( 478 body->push_back( new ReturnStmt( noLabels, 477 479 new ConstantExpr( Constant::from_bool( false ) ) ) ); 478 480 … … 484 486 Statement * wraps, 485 487 FunctionDecl * resume_handler ) { 486 CompoundStmt * body = new CompoundStmt( );488 CompoundStmt * body = new CompoundStmt( noLabels ); 487 489 488 490 // struct __try_resume_node __resume_node 489 // __attribute__((cleanup( __cfa abi_ehm__try_resume_cleanup )));491 // __attribute__((cleanup( __cfaehm__try_resume_cleanup ))); 490 492 // ** unwinding of the stack here could cause problems ** 491 493 // ** however I don't think that can happen currently ** 492 // __cfa abi_ehm__try_resume_setup( &__resume_node, resume_handler );494 // __cfaehm__try_resume_setup( &__resume_node, resume_handler ); 493 495 494 496 std::list< Attribute * > attributes; … … 496 498 std::list< Expression * > attr_params; 497 499 attr_params.push_back( new NameExpr( 498 "__cfa abi_ehm__try_resume_cleanup" ) );500 "__cfaehm__try_resume_cleanup" ) ); 499 501 attributes.push_back( new Attribute( "cleanup", attr_params ) ); 500 502 } … … 515 517 516 518 UntypedExpr *setup = new UntypedExpr( new NameExpr( 517 "__cfa abi_ehm__try_resume_setup" ) );519 "__cfaehm__try_resume_setup" ) ); 518 520 setup->get_args().push_back( new AddressExpr( nameOf( obj ) ) ); 519 521 setup->get_args().push_back( nameOf( resume_handler ) ); 520 522 521 body->push_back( new ExprStmt( setup ) );523 body->push_back( new ExprStmt( noLabels, setup ) ); 522 524 523 525 body->push_back( wraps ); … … 540 542 ObjectDecl * ExceptionMutatorCore::create_finally_hook( 541 543 FunctionDecl * finally_wrapper ) { 542 // struct __cfa abi_ehm__cleanup_hook __finally_hook544 // struct __cfaehm__cleanup_hook __finally_hook 543 545 // __attribute__((cleanup( finally_wrapper ))); 544 546 … … 594 596 // Skip children? 595 597 return; 596 } else if ( structDecl->get_name() == "__cfa abi_ehm__base_exception_t" ) {598 } else if ( structDecl->get_name() == "__cfaehm__base_exception_t" ) { 597 599 assert( nullptr == except_decl ); 598 600 except_decl = structDecl; 599 601 init_func_types(); 600 } else if ( structDecl->get_name() == "__cfa abi_ehm__try_resume_node" ) {602 } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) { 601 603 assert( nullptr == node_decl ); 602 604 node_decl = structDecl; 603 } else if ( structDecl->get_name() == "__cfa abi_ehm__cleanup_hook" ) {605 } else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) { 604 606 assert( nullptr == hook_decl ); 605 607 hook_decl = structDecl; … … 644 646 // Generate a prefix for the function names? 645 647 646 CompoundStmt * block = new CompoundStmt( );648 CompoundStmt * block = new CompoundStmt( noLabels ); 647 649 CompoundStmt * inner = take_try_block( tryStmt ); 648 650 -
src/ControlStruct/ForExprMutator.cc
rc13e8dc8 r9c35431 29 29 // Create compound statement, move initializers outside, 30 30 // the resut of the original stays as is. 31 CompoundStmt *block = new CompoundStmt( );31 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 32 32 std::list<Statement *> &stmts = block->get_kids(); 33 33 stmts.splice( stmts.end(), init ); -
src/ControlStruct/LabelFixer.cc
rc13e8dc8 r9c35431 37 37 } 38 38 39 void LabelFixer:: previsit( FunctionDecl *) {39 void LabelFixer::visit( FunctionDecl *functionDecl ) { 40 40 // need to go into a nested function in a fresh state 41 GuardValue( labelTable );41 std::map < Label, Entry *> oldLabelTable = labelTable; 42 42 labelTable.clear(); 43 }44 43 45 void LabelFixer::postvisit( FunctionDecl * functionDecl ) { 44 maybeAccept( functionDecl->get_statements(), *this ); 45 46 46 MLEMutator mlemut( resolveJumps(), generator ); 47 47 functionDecl->acceptMutator( mlemut ); 48 49 // and remember the outer function's labels when 50 // returning to it 51 labelTable = oldLabelTable; 48 52 } 49 53 50 54 // prune to at most one label definition for each statement 51 void LabelFixer:: previsit( Statement *stmt ) {55 void LabelFixer::visit( Statement *stmt ) { 52 56 std::list< Label > &labels = stmt->get_labels(); 53 57 … … 58 62 } 59 63 60 void LabelFixer:: previsit( BranchStmt *branchStmt ) {61 previsit( ( Statement *)branchStmt );64 void LabelFixer::visit( BranchStmt *branchStmt ) { 65 visit ( ( Statement * )branchStmt ); 62 66 63 67 // for labeled branches, add an entry to the label table … … 68 72 } 69 73 70 void LabelFixer::previsit( LabelAddressExpr * addrExpr ) { 71 Label & target = addrExpr->arg; 72 assert( target != "" ); 73 setLabelsUsg( target, addrExpr ); 74 void LabelFixer::visit( UntypedExpr *untyped ) { 75 if ( NameExpr * func = dynamic_cast< NameExpr * >( untyped->get_function() ) ) { 76 if ( func->get_name() == "&&" ) { 77 NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() ); 78 Label target = arg->get_name(); 79 assert( target != "" ); 80 setLabelsUsg( target, untyped ); 81 } else { 82 Visitor::visit( untyped ); 83 } 84 } 74 85 } 75 86 -
src/ControlStruct/LabelFixer.h
rc13e8dc8 r9c35431 19 19 #include <map> // for map 20 20 21 #include "Common/PassVisitor.h"22 21 #include "Common/SemanticError.h" // for SemanticError 23 22 #include "SynTree/Label.h" // for Label … … 27 26 namespace ControlStruct { 28 27 /// normalizes label definitions and generates multi-level exit labels 29 class LabelGenerator;28 class LabelGenerator; 30 29 31 class LabelFixer final : public WithGuards { 30 class LabelFixer final : public Visitor { 31 typedef Visitor Parent; 32 32 public: 33 33 LabelFixer( LabelGenerator *gen = 0 ); … … 35 35 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError ); 36 36 37 using Visitor::visit; 38 37 39 // Declarations 38 void previsit( FunctionDecl *functionDecl ); 39 void postvisit( FunctionDecl *functionDecl ); 40 virtual void visit( FunctionDecl *functionDecl ) override; 40 41 41 42 // Statements 42 void previsit( Statement *stmt ); 43 void previsit( BranchStmt *branchStmt ); 43 void visit( Statement *stmt ); 44 44 45 // Expressions 46 void previsit( LabelAddressExpr *addrExpr ); 45 virtual void visit( CompoundStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 46 virtual void visit( NullStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 47 virtual void visit( ExprStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 48 virtual void visit( IfStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 49 virtual void visit( WhileStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 50 virtual void visit( ForStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 51 virtual void visit( SwitchStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 52 virtual void visit( CaseStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 53 virtual void visit( ReturnStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 54 virtual void visit( TryStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 55 virtual void visit( CatchStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 56 virtual void visit( DeclStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 57 virtual void visit( BranchStmt *branchStmt ) override; 58 virtual void visit( UntypedExpr *untyped ) override; 47 59 48 60 Label setLabelsDef( std::list< Label > &, Statement *definition ); -
src/ControlStruct/MLEMutator.cc
rc13e8dc8 r9c35431 149 149 150 150 if ( CaseStmt * c = dynamic_cast< CaseStmt * >( statements.back() ) ) { 151 Statement * stmt = new BranchStmt( Label("brkLabel"), BranchStmt::Break ); 152 stmt->labels.push_back( brkLabel ); 153 c->get_statements().push_back( stmt ); 151 std::list<Label> temp; temp.push_back( brkLabel ); 152 c->get_statements().push_back( new BranchStmt( temp, Label("brkLabel"), BranchStmt::Break ) ); 154 153 } else assert(0); // as of this point, all statements of a switch are still CaseStmts 155 154 } // if … … 233 232 // transform break/continue statements into goto to simplify later handling of branches 234 233 delete branchStmt; 235 return new BranchStmt( exitLabel, BranchStmt::Goto );234 return new BranchStmt( std::list<Label>(), exitLabel, BranchStmt::Goto ); 236 235 } 237 236 … … 240 239 CompoundStmt *newBody; 241 240 if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) { 242 newBody = new CompoundStmt( );241 newBody = new CompoundStmt( std::list< Label >() ); 243 242 newBody->get_kids().push_back( bodyLoop ); 244 243 } // if -
src/ControlStruct/Mutate.cc
rc13e8dc8 r9c35431 24 24 #include "SynTree/Declaration.h" // for Declaration 25 25 #include "SynTree/Mutator.h" // for mutateAll 26 //#include "ExceptMutator.h" 26 27 27 28 #include "Common/PassVisitor.h" // for PassVisitor … … 36 37 37 38 // normalizes label definitions and generates multi-level exit labels 38 PassVisitor<LabelFixer> lfix; 39 LabelFixer lfix; 40 41 //ExceptMutator exc; 39 42 40 43 mutateAll( translationUnit, formut ); 41 44 acceptAll( translationUnit, lfix ); 45 //mutateAll( translationUnit, exc ); 42 46 } 43 47 } // namespace CodeGen -
src/GenPoly/Box.cc
rc13e8dc8 r9c35431 49 49 #include "SynTree/Expression.h" // for ApplicationExpr, UntypedExpr 50 50 #include "SynTree/Initializer.h" // for SingleInit, Initializer, Lis... 51 #include "SynTree/Label.h" // for Label 51 #include "SynTree/Label.h" // for Label, noLabels 52 52 #include "SynTree/Mutator.h" // for maybeMutate, Mutator, mutateAll 53 53 #include "SynTree/Statement.h" // for ExprStmt, DeclStmt, ReturnStmt … … 293 293 FunctionDecl *layoutDecl = new FunctionDecl( layoutofName( typeDecl ), 294 294 functionNesting > 0 ? Type::StorageClasses() : Type::StorageClasses( Type::Static ), 295 LinkageSpec::AutoGen, layoutFnType, new CompoundStmt( ),295 LinkageSpec::AutoGen, layoutFnType, new CompoundStmt( noLabels ), 296 296 std::list< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ); 297 297 layoutDecl->fixUniqueId(); … … 321 321 /// makes an if-statement with a single-expression if-block and no then block 322 322 Statement *makeCond( Expression *cond, Expression *ifPart ) { 323 return new IfStmt( cond, new ExprStmt(ifPart ), 0 );323 return new IfStmt( noLabels, cond, new ExprStmt( noLabels, ifPart ), 0 ); 324 324 } 325 325 … … 340 340 /// adds an expression to a compound statement 341 341 void addExpr( CompoundStmt *stmts, Expression *expr ) { 342 stmts->get_kids().push_back( new ExprStmt( expr ) );342 stmts->get_kids().push_back( new ExprStmt( noLabels, expr ) ); 343 343 } 344 344 … … 629 629 ObjectDecl *Pass1::makeTemporary( Type *type ) { 630 630 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), Type::StorageClasses(), LinkageSpec::C, 0, type, 0 ); 631 stmtsToAddBefore.push_back( new DeclStmt( n ewObj ) );631 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) ); 632 632 return newObj; 633 633 } … … 740 740 ObjectDecl *newObj = ObjectDecl::newObject( tempNamer.newName(), newType, nullptr ); 741 741 newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right??? 742 stmtsToAddBefore.push_back( new DeclStmt( n ewObj ) );742 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) ); 743 743 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); // TODO: why doesn't this just use initialization syntax? 744 744 assign->get_args().push_back( new VariableExpr( newObj ) ); 745 745 assign->get_args().push_back( arg ); 746 stmtsToAddBefore.push_back( new ExprStmt( assign ) );746 stmtsToAddBefore.push_back( new ExprStmt( noLabels, assign ) ); 747 747 arg = new AddressExpr( new VariableExpr( newObj ) ); 748 748 } // if … … 888 888 // void return 889 889 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars ); 890 bodyStmt = new ExprStmt( adapteeApp );890 bodyStmt = new ExprStmt( noLabels, adapteeApp ); 891 891 } else if ( isDynType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { 892 892 // return type T … … 900 900 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars ); 901 901 assign->get_args().push_back( adapteeApp ); 902 bodyStmt = new ExprStmt( assign );902 bodyStmt = new ExprStmt( noLabels, assign ); 903 903 } else { 904 904 // adapter for a function that returns a monomorphic value 905 905 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars ); 906 bodyStmt = new ReturnStmt( adapteeApp );906 bodyStmt = new ReturnStmt( noLabels, adapteeApp ); 907 907 } // if 908 CompoundStmt *adapterBody = new CompoundStmt( );908 CompoundStmt *adapterBody = new CompoundStmt( noLabels ); 909 909 adapterBody->get_kids().push_back( bodyStmt ); 910 910 std::string adapterName = makeAdapterName( mangleName ); … … 952 952 std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) ); 953 953 adapter = answer.first; 954 stmtsToAddBefore.push_back( new DeclStmt( n ewAdapter ) );954 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newAdapter ) ); 955 955 } // if 956 956 assert( adapter != adapters.end() ); … … 1279 1279 retval->set_name( "_retval" ); 1280 1280 } 1281 functionDecl->get_statements()->get_kids().push_front( new DeclStmt( retval ) );1281 functionDecl->get_statements()->get_kids().push_front( new DeclStmt( noLabels, retval ) ); 1282 1282 DeclarationWithType * newRet = retval->clone(); // for ownership purposes 1283 1283 ftype->get_returnVals().front() = newRet; … … 1519 1519 // (alloca was previously used, but can't be safely used in loops) 1520 1520 ObjectDecl *newBuf = ObjectDecl::newObject( bufNamer.newName(), polyToMonoType( objectDecl->type ), nullptr ); 1521 stmtsToAddBefore.push_back( new DeclStmt( n ewBuf ) );1521 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newBuf ) ); 1522 1522 1523 1523 delete objectDecl->get_init(); … … 1598 1598 ObjectDecl *PolyGenericCalculator::makeVar( const std::string &name, Type *type, Initializer *init ) { 1599 1599 ObjectDecl *newObj = new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, 0, type, init ); 1600 stmtsToAddBefore.push_back( new DeclStmt( n ewObj ) );1600 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) ); 1601 1601 return newObj; 1602 1602 } … … 1677 1677 addOtypeParamsToLayoutCall( layoutCall, otypeParams ); 1678 1678 1679 stmtsToAddBefore.push_back( new ExprStmt( layoutCall ) );1679 stmtsToAddBefore.push_back( new ExprStmt( noLabels, layoutCall ) ); 1680 1680 } 1681 1681 … … 1703 1703 addOtypeParamsToLayoutCall( layoutCall, otypeParams ); 1704 1704 1705 stmtsToAddBefore.push_back( new ExprStmt( layoutCall ) );1705 stmtsToAddBefore.push_back( new ExprStmt( noLabels, layoutCall ) ); 1706 1706 1707 1707 return true; -
src/GenPoly/InstantiateGeneric.cc
rc13e8dc8 r9c35431 453 453 return false; 454 454 } 455 456 AggregateDecl * getAggr( Type * t ) { 457 if ( StructInstType * inst = dynamic_cast< StructInstType * >( t ) ) { 458 return inst->baseStruct; 459 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( t ) ) { 460 return inst->baseUnion; 461 } 462 assertf( false, "Non-aggregate type: %s", toString( t ).c_str() ); 463 } 455 464 } 456 465 … … 460 469 if ( isGenericType( memberExpr->aggregate->result ) ) { 461 470 // find the location of the member 462 AggregateDecl * aggr = memberExpr->aggregate->result->getAggr();471 AggregateDecl * aggr = getAggr( memberExpr->aggregate->result ); 463 472 std::list< Declaration * > & members = aggr->members; 464 473 memberIndex = std::distance( members.begin(), std::find( members.begin(), members.end(), memberExpr->member ) ); … … 470 479 if ( memberIndex != -1 ) { 471 480 // using the location from the generic type, find the member in the instantiation and rebuild the member expression 472 AggregateDecl * aggr = memberExpr->aggregate->result->getAggr();481 AggregateDecl * aggr = getAggr( memberExpr->aggregate->result ); 473 482 assertf( memberIndex < (int)aggr->members.size(), "Instantiation somehow has fewer members than the generic type." ); 474 483 Declaration * member = *std::next( aggr->members.begin(), memberIndex ); … … 517 526 Expression * init = new CastExpr( new AddressExpr( memberExpr ), new PointerType( Type::Qualifiers(), concType->clone() ) ); 518 527 ObjectDecl * tmp = ObjectDecl::newObject( tmpNamer.newName(), new ReferenceType( Type::Qualifiers(), concType ), new SingleInit( init ) ); 519 stmtsToAddBefore.push_back( new DeclStmt( tmp ) );528 stmtsToAddBefore.push_back( new DeclStmt( noLabels, tmp ) ); 520 529 return new VariableExpr( tmp ); 521 530 } else { -
src/GenPoly/Specialize.cc
rc13e8dc8 r9c35431 35 35 #include "SynTree/Declaration.h" // for FunctionDecl, DeclarationWit... 36 36 #include "SynTree/Expression.h" // for ApplicationExpr, Expression 37 #include "SynTree/Label.h" // for Label 37 #include "SynTree/Label.h" // for Label, noLabels 38 38 #include "SynTree/Mutator.h" // for mutateAll 39 39 #include "SynTree/Statement.h" // for CompoundStmt, DeclStmt, Expr... … … 234 234 } // if 235 235 // create new thunk with same signature as formal type (C linkage, empty body) 236 FunctionDecl *thunkFunc = new FunctionDecl( thunkNamer.newName(), Type::StorageClasses(), LinkageSpec::C, newType, new CompoundStmt( ) );236 FunctionDecl *thunkFunc = new FunctionDecl( thunkNamer.newName(), Type::StorageClasses(), LinkageSpec::C, newType, new CompoundStmt( noLabels ) ); 237 237 thunkFunc->fixUniqueId(); 238 238 … … 287 287 Statement *appStmt; 288 288 if ( funType->returnVals.empty() ) { 289 appStmt = new ExprStmt( appExpr );290 } else { 291 appStmt = new ReturnStmt( appExpr );289 appStmt = new ExprStmt( noLabels, appExpr ); 290 } else { 291 appStmt = new ReturnStmt( noLabels, appExpr ); 292 292 } // if 293 293 thunkFunc->statements->kids.push_back( appStmt ); 294 294 295 295 // add thunk definition to queue of statements to add 296 stmtsToAddBefore.push_back( new DeclStmt( thunkFunc ) );296 stmtsToAddBefore.push_back( new DeclStmt( noLabels, thunkFunc ) ); 297 297 // return address of thunk function as replacement expression 298 298 return new AddressExpr( new VariableExpr( thunkFunc ) ); -
src/InitTweak/FixGlobalInit.cc
rc13e8dc8 r9c35431 20 20 #include <algorithm> // for replace_if 21 21 22 #include "Common/PassVisitor.h"23 22 #include "Common/SemanticError.h" // for SemanticError 24 23 #include "Common/UniqueName.h" // for UniqueName … … 30 29 #include "SynTree/Expression.h" // for ConstantExpr, Expression (ptr only) 31 30 #include "SynTree/Initializer.h" // for ConstructorInit, Initializer 32 #include "SynTree/Label.h" // for Label 31 #include "SynTree/Label.h" // for Label, noLabels 33 32 #include "SynTree/Statement.h" // for CompoundStmt, Statement (ptr only) 34 33 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Functi... … … 36 35 37 36 namespace InitTweak { 38 class GlobalFixer : public WithShortCircuiting{37 class GlobalFixer : public Visitor { 39 38 public: 40 39 GlobalFixer( const std::string & name, bool inLibrary ); 41 40 42 v oid previsit( ObjectDecl *objDecl );43 v oid previsit( FunctionDecl *functionDecl );44 v oid previsit( StructDecl *aggregateDecl );45 v oid previsit( UnionDecl *aggregateDecl );46 v oid previsit( EnumDecl *aggregateDecl );47 v oid previsit( TraitDecl *aggregateDecl );48 v oid previsit( TypeDecl *typeDecl );41 virtual void visit( ObjectDecl *objDecl ); 42 virtual void visit( FunctionDecl *functionDecl ); 43 virtual void visit( StructDecl *aggregateDecl ); 44 virtual void visit( UnionDecl *aggregateDecl ); 45 virtual void visit( EnumDecl *aggregateDecl ); 46 virtual void visit( TraitDecl *aggregateDecl ); 47 virtual void visit( TypeDecl *typeDecl ); 49 48 50 49 UniqueName tempNamer; … … 54 53 55 54 void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) { 56 PassVisitor<GlobalFixer> visitor( name, inLibrary ); 57 acceptAll( translationUnit, visitor ); 58 GlobalFixer & fixer = visitor.pass; 55 GlobalFixer fixer( name, inLibrary ); 56 acceptAll( translationUnit, fixer ); 59 57 // don't need to include function if it's empty 60 58 if ( fixer.initFunction->get_statements()->get_kids().empty() ) { … … 94 92 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) ); 95 93 } 96 initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( ) );94 initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) ); 97 95 initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) ); 98 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( ) );96 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) ); 99 97 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) ); 100 98 } 101 99 102 void GlobalFixer:: previsit( ObjectDecl *objDecl ) {100 void GlobalFixer::visit( ObjectDecl *objDecl ) { 103 101 std::list< Statement * > & initStatements = initFunction->get_statements()->get_kids(); 104 102 std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids(); … … 136 134 137 135 // only modify global variables 138 void GlobalFixer:: previsit( FunctionDecl * ) { visit_children = false;}139 void GlobalFixer:: previsit( StructDecl * ) { visit_children = false;}140 void GlobalFixer:: previsit( UnionDecl * ) { visit_children = false;}141 void GlobalFixer:: previsit( EnumDecl * ) { visit_children = false;}142 void GlobalFixer:: previsit( TraitDecl * ) { visit_children = false;}143 void GlobalFixer:: previsit( TypeDecl * ) { visit_children = false;}136 void GlobalFixer::visit( __attribute__((unused)) FunctionDecl *functionDecl ) {} 137 void GlobalFixer::visit( __attribute__((unused)) StructDecl *aggregateDecl ) {} 138 void GlobalFixer::visit( __attribute__((unused)) UnionDecl *aggregateDecl ) {} 139 void GlobalFixer::visit( __attribute__((unused)) EnumDecl *aggregateDecl ) {} 140 void GlobalFixer::visit( __attribute__((unused)) TraitDecl *aggregateDecl ) {} 141 void GlobalFixer::visit( __attribute__((unused)) TypeDecl *typeDecl ) {} 144 142 145 143 } // namespace InitTweak -
src/InitTweak/FixInit.cc
rc13e8dc8 r9c35431 49 49 #include "SynTree/Expression.h" // for UniqueExpr, VariableExpr, Unty... 50 50 #include "SynTree/Initializer.h" // for ConstructorInit, SingleInit 51 #include "SynTree/Label.h" // for Label, operator<51 #include "SynTree/Label.h" // for Label, noLabels, operator< 52 52 #include "SynTree/Mutator.h" // for mutateAll, Mutator, maybeMutate 53 53 #include "SynTree/Statement.h" // for ExprStmt, CompoundStmt, Branch... … … 547 547 // add all temporary declarations and their constructors 548 548 for ( ObjectDecl * obj : tempDecls ) { 549 stmtsToAddBefore.push_back( new DeclStmt( obj ) );549 stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) ); 550 550 } // for 551 551 for ( ObjectDecl * obj : returnDecls ) { 552 stmtsToAddBefore.push_back( new DeclStmt( obj ) );552 stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) ); 553 553 } // for 554 554 555 555 // add destructors after current statement 556 556 for ( Expression * dtor : dtors ) { 557 stmtsToAddAfter.push_back( new ExprStmt( dtor ) );557 stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) ); 558 558 } // for 559 559 … … 601 601 if ( ! result->isVoid() ) { 602 602 for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) { 603 stmtsToAddBefore.push_back( new DeclStmt( obj ) );603 stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) ); 604 604 } // for 605 605 // add destructors after current statement 606 606 for ( Expression * dtor : stmtExpr->get_dtors() ) { 607 stmtsToAddAfter.push_back( new ExprStmt( dtor ) );607 stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) ); 608 608 } // for 609 609 // must have a non-empty body, otherwise it wouldn't have a result 610 610 assert( ! stmts.empty() ); 611 611 assert( ! stmtExpr->get_returnDecls().empty() ); 612 stmts.push_back( new ExprStmt( n ew VariableExpr( stmtExpr->get_returnDecls().front() ) ) );612 stmts.push_back( new ExprStmt( noLabels, new VariableExpr( stmtExpr->get_returnDecls().front() ) ) ); 613 613 stmtExpr->get_returnDecls().clear(); 614 614 stmtExpr->get_dtors().clear(); … … 739 739 740 740 // generate body of if 741 CompoundStmt * initStmts = new CompoundStmt( );741 CompoundStmt * initStmts = new CompoundStmt( noLabels ); 742 742 std::list< Statement * > & body = initStmts->get_kids(); 743 743 body.push_back( ctor ); 744 body.push_back( new ExprStmt( setTrue ) );744 body.push_back( new ExprStmt( noLabels, setTrue ) ); 745 745 746 746 // put it all together 747 IfStmt * ifStmt = new IfStmt( n ew VariableExpr( isUninitializedVar ), initStmts, 0 );748 stmtsToAddAfter.push_back( new DeclStmt( isUninitializedVar ) );747 IfStmt * ifStmt = new IfStmt( noLabels, new VariableExpr( isUninitializedVar ), initStmts, 0 ); 748 stmtsToAddAfter.push_back( new DeclStmt( noLabels, isUninitializedVar ) ); 749 749 stmtsToAddAfter.push_back( ifStmt ); 750 750 … … 761 761 762 762 // void __objName_dtor_atexitN(...) {...} 763 FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( ) );763 FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) ); 764 764 dtorCaller->fixUniqueId(); 765 765 dtorCaller->get_statements()->push_back( dtorStmt ); … … 769 769 callAtexit->get_args().push_back( new VariableExpr( dtorCaller ) ); 770 770 771 body.push_back( new ExprStmt( callAtexit ) );771 body.push_back( new ExprStmt( noLabels, callAtexit ) ); 772 772 773 773 // hoist variable and dtor caller decls to list of decls that will be added into global scope -
src/InitTweak/InitTweak.cc
rc13e8dc8 r9c35431 5 5 #include <memory> // for __shared_ptr 6 6 7 #include "Common/PassVisitor.h"8 7 #include "Common/SemanticError.h" // for SemanticError 9 8 #include "Common/UniqueName.h" // for UniqueName … … 20 19 #include "SynTree/Expression.h" // for Expression, UntypedExpr, Applicati... 21 20 #include "SynTree/Initializer.h" // for Initializer, ListInit, Designation 22 #include "SynTree/Label.h" // for Label 21 #include "SynTree/Label.h" // for Label, noLabels 23 22 #include "SynTree/Statement.h" // for CompoundStmt, ExprStmt, BranchStmt 24 23 #include "SynTree/Type.h" // for FunctionType, ArrayType, PointerType … … 30 29 namespace InitTweak { 31 30 namespace { 32 struct HasDesignations : public WithShortCircuiting { 31 class HasDesignations : public Visitor { 32 public: 33 33 bool hasDesignations = false; 34 35 void previsit( BaseSyntaxNode * ) { 36 // short circuit if we already know there are designations 37 if ( hasDesignations ) visit_children = false; 38 } 39 40 void previsit( Designation * des ) { 41 // short circuit if we already know there are designations 42 if ( hasDesignations ) visit_children = false; 43 else if ( ! des->get_designators().empty() ) { 44 hasDesignations = true; 45 visit_children = false; 46 } 34 virtual void visit( Designation * des ) { 35 if ( ! des->get_designators().empty() ) hasDesignations = true; 36 else Visitor::visit( des ); 47 37 } 48 38 }; 49 39 50 struct InitDepthChecker : public WithGuards { 40 class InitDepthChecker : public Visitor { 41 public: 51 42 bool depthOkay = true; 52 43 Type * type; … … 60 51 maxDepth++; 61 52 } 62 v oid previsit( ListInit *) {53 virtual void visit( ListInit * listInit ) { 63 54 curDepth++; 64 GuardAction( [this]() { curDepth--; } );65 55 if ( curDepth > maxDepth ) depthOkay = false; 56 Visitor::visit( listInit ); 57 curDepth--; 66 58 } 67 59 }; 68 60 69 struct InitFlattener : public WithShortCircuiting { 70 void previsit( SingleInit * singleInit ) { 71 visit_children = false; 72 argList.push_back( singleInit->value->clone() ); 73 } 61 class InitFlattener : public Visitor { 62 public: 63 virtual void visit( SingleInit * singleInit ); 64 virtual void visit( ListInit * listInit ); 74 65 std::list< Expression * > argList; 75 66 }; 76 67 68 void InitFlattener::visit( SingleInit * singleInit ) { 69 argList.push_back( singleInit->get_value()->clone() ); 70 } 71 72 void InitFlattener::visit( ListInit * listInit ) { 73 // flatten nested list inits 74 std::list<Initializer*>::iterator it = listInit->begin(); 75 for ( ; it != listInit->end(); ++it ) { 76 (*it)->accept( *this ); 77 } 78 } 77 79 } 78 80 79 81 std::list< Expression * > makeInitList( Initializer * init ) { 80 PassVisitor<InitFlattener>flattener;82 InitFlattener flattener; 81 83 maybeAccept( init, flattener ); 82 return flattener. pass.argList;84 return flattener.argList; 83 85 } 84 86 85 87 bool isDesignated( Initializer * init ) { 86 PassVisitor<HasDesignations>finder;88 HasDesignations finder; 87 89 maybeAccept( init, finder ); 88 return finder. pass.hasDesignations;90 return finder.hasDesignations; 89 91 } 90 92 91 93 bool checkInitDepth( ObjectDecl * objDecl ) { 92 PassVisitor<InitDepthChecker> checker( objDecl->type);93 maybeAccept( objDecl-> init, checker );94 return checker. pass.depthOkay;94 InitDepthChecker checker( objDecl->get_type() ); 95 maybeAccept( objDecl->get_init(), checker ); 96 return checker.depthOkay; 95 97 } 96 98 … … 193 195 callExpr->get_args().splice( callExpr->get_args().end(), args ); 194 196 195 *out++ = new IfStmt( cond, new ExprStmt(callExpr ), nullptr );197 *out++ = new IfStmt( noLabels, cond, new ExprStmt( noLabels, callExpr ), nullptr ); 196 198 197 199 UntypedExpr * increment = new UntypedExpr( new NameExpr( "++?" ) ); 198 200 increment->get_args().push_back( index->clone() ); 199 *out++ = new ExprStmt( increment );201 *out++ = new ExprStmt( noLabels, increment ); 200 202 } 201 203 … … 242 244 std::list< Statement * > stmts; 243 245 build( callExpr, idx, idxEnd, init, back_inserter( stmts ) ); 244 stmts.push_back( new BranchStmt( switchLabel, BranchStmt::Break ) );245 CaseStmt * caseStmt = new CaseStmt( condition, stmts );246 stmts.push_back( new BranchStmt( noLabels, switchLabel, BranchStmt::Break ) ); 247 CaseStmt * caseStmt = new CaseStmt( noLabels, condition, stmts ); 246 248 branches.push_back( caseStmt ); 247 249 } 248 *out++ = new SwitchStmt( index->clone(), branches );249 *out++ = new NullStmt( { switchLabel } );250 *out++ = new SwitchStmt( noLabels, index->clone(), branches ); 251 *out++ = new NullStmt( std::list<Label>{ switchLabel } ); 250 252 } 251 253 } … … 260 262 Statement * InitImpl::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) { 261 263 if ( ! init ) return nullptr; 262 CompoundStmt * block = new CompoundStmt( );264 CompoundStmt * block = new CompoundStmt( noLabels ); 263 265 build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) ); 264 266 if ( block->get_kids().empty() ) { … … 307 309 } 308 310 309 struct CallFinder { 311 class CallFinder : public Visitor { 312 public: 313 typedef Visitor Parent; 310 314 CallFinder( const std::list< std::string > & names ) : names( names ) {} 311 315 312 v oid postvisit( ApplicationExpr * appExpr ) {316 virtual void visit( ApplicationExpr * appExpr ) { 313 317 handleCallExpr( appExpr ); 314 318 } 315 319 316 v oid postvisit( UntypedExpr * untypedExpr ) {320 virtual void visit( UntypedExpr * untypedExpr ) { 317 321 handleCallExpr( untypedExpr ); 318 322 } … … 324 328 template< typename CallExpr > 325 329 void handleCallExpr( CallExpr * expr ) { 330 Parent::visit( expr ); 326 331 std::string fname = getFunctionName( expr ); 327 332 if ( std::find( names.begin(), names.end(), fname ) != names.end() ) { … … 332 337 333 338 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ) { 334 static PassVisitor<CallFinder>finder( std::list< std::string >{ "?{}", "^?{}" } );335 finder. pass.matches = &matches;339 static CallFinder finder( std::list< std::string >{ "?{}", "^?{}" } ); 340 finder.matches = &matches; 336 341 maybeAccept( stmt, finder ); 337 342 } … … 539 544 } 540 545 541 struct ConstExprChecker : public WithShortCircuiting { 542 // most expressions are not const expr 543 void previsit( Expression * ) { isConstExpr = false; visit_children = false; } 544 545 void previsit( AddressExpr *addressExpr ) { 546 visit_children = false; 547 546 class ConstExprChecker : public Visitor { 547 public: 548 ConstExprChecker() : isConstExpr( true ) {} 549 550 using Visitor::visit; 551 552 virtual void visit( ApplicationExpr * ) { isConstExpr = false; } 553 virtual void visit( UntypedExpr * ) { isConstExpr = false; } 554 virtual void visit( NameExpr * ) { isConstExpr = false; } 555 // virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 556 virtual void visit( AddressExpr *addressExpr ) { 548 557 // address of a variable or member expression is constexpr 549 558 Expression * arg = addressExpr->get_arg(); 550 559 if ( ! dynamic_cast< NameExpr * >( arg) && ! dynamic_cast< VariableExpr * >( arg ) && ! dynamic_cast< MemberExpr * >( arg ) && ! dynamic_cast< UntypedMemberExpr * >( arg ) ) isConstExpr = false; 551 560 } 552 553 // these expressions may be const expr, depending on their children 554 void previsit( SizeofExpr * ) {} 555 void previsit( AlignofExpr * ) {} 556 void previsit( UntypedOffsetofExpr * ) {} 557 void previsit( OffsetofExpr * ) {} 558 void previsit( OffsetPackExpr * ) {} 559 void previsit( AttrExpr * ) {} 560 void previsit( CommaExpr * ) {} 561 void previsit( LogicalExpr * ) {} 562 void previsit( ConditionalExpr * ) {} 563 void previsit( CastExpr * ) {} 564 void previsit( ConstantExpr * ) {} 565 566 bool isConstExpr = true; 561 virtual void visit( UntypedMemberExpr * ) { isConstExpr = false; } 562 virtual void visit( MemberExpr * ) { isConstExpr = false; } 563 virtual void visit( VariableExpr * ) { isConstExpr = false; } 564 // these might be okay? 565 // virtual void visit( SizeofExpr *sizeofExpr ); 566 // virtual void visit( AlignofExpr *alignofExpr ); 567 // virtual void visit( UntypedOffsetofExpr *offsetofExpr ); 568 // virtual void visit( OffsetofExpr *offsetofExpr ); 569 // virtual void visit( OffsetPackExpr *offsetPackExpr ); 570 // virtual void visit( AttrExpr *attrExpr ); 571 // virtual void visit( CommaExpr *commaExpr ); 572 // virtual void visit( LogicalExpr *logicalExpr ); 573 // virtual void visit( ConditionalExpr *conditionalExpr ); 574 virtual void visit( TypeExpr * ) { isConstExpr = false; } 575 virtual void visit( AsmExpr * ) { isConstExpr = false; } 576 virtual void visit( UntypedValofExpr * ) { isConstExpr = false; } 577 virtual void visit( CompoundLiteralExpr * ) { isConstExpr = false; } 578 virtual void visit( UntypedTupleExpr * ) { isConstExpr = false; } 579 virtual void visit( TupleExpr * ) { isConstExpr = false; } 580 virtual void visit( TupleAssignExpr * ) { isConstExpr = false; } 581 582 bool isConstExpr; 567 583 }; 568 584 569 585 bool isConstExpr( Expression * expr ) { 570 586 if ( expr ) { 571 PassVisitor<ConstExprChecker>checker;587 ConstExprChecker checker; 572 588 expr->accept( checker ); 573 return checker. pass.isConstExpr;589 return checker.isConstExpr; 574 590 } 575 591 return true; … … 578 594 bool isConstExpr( Initializer * init ) { 579 595 if ( init ) { 580 PassVisitor<ConstExprChecker>checker;596 ConstExprChecker checker; 581 597 init->accept( checker ); 582 return checker. pass.isConstExpr;598 return checker.isConstExpr; 583 599 } // if 584 600 // for all intents and purposes, no initializer means const expr -
src/MakeLibCfa.cc
rc13e8dc8 r9c35431 116 116 } // for 117 117 118 funcDecl->set_statements( new CompoundStmt( ) );118 funcDecl->set_statements( new CompoundStmt( std::list< Label >() ) ); 119 119 newDecls.push_back( funcDecl ); 120 120 … … 130 130 case CodeGen::OT_INFIXASSIGN: 131 131 // return the recursive call 132 stmt = new ReturnStmt( n ewExpr );132 stmt = new ReturnStmt( noLabels, newExpr ); 133 133 break; 134 134 case CodeGen::OT_CTOR: 135 135 case CodeGen::OT_DTOR: 136 136 // execute the recursive call 137 stmt = new ExprStmt( n ewExpr );137 stmt = new ExprStmt( noLabels, newExpr ); 138 138 break; 139 139 case CodeGen::OT_CONSTANT: -
src/Makefile.in
rc13e8dc8 r9c35431 215 215 SymTab/driver_cfa_cpp-Validate.$(OBJEXT) \ 216 216 SymTab/driver_cfa_cpp-FixFunction.$(OBJEXT) \ 217 SymTab/driver_cfa_cpp-ImplementationType.$(OBJEXT) \ 218 SymTab/driver_cfa_cpp-TypeEquality.$(OBJEXT) \ 217 219 SymTab/driver_cfa_cpp-Autogen.$(OBJEXT) \ 218 220 SynTree/driver_cfa_cpp-Type.$(OBJEXT) \ … … 512 514 ResolvExpr/CurrentObject.cc ResolvExpr/ExplodedActual.cc \ 513 515 SymTab/Indexer.cc SymTab/Mangler.cc SymTab/Validate.cc \ 514 SymTab/FixFunction.cc SymTab/Autogen.cc SynTree/Type.cc \ 516 SymTab/FixFunction.cc SymTab/ImplementationType.cc \ 517 SymTab/TypeEquality.cc SymTab/Autogen.cc SynTree/Type.cc \ 515 518 SynTree/VoidType.cc SynTree/BasicType.cc \ 516 519 SynTree/PointerType.cc SynTree/ArrayType.cc \ … … 841 844 SymTab/driver_cfa_cpp-FixFunction.$(OBJEXT): SymTab/$(am__dirstamp) \ 842 845 SymTab/$(DEPDIR)/$(am__dirstamp) 846 SymTab/driver_cfa_cpp-ImplementationType.$(OBJEXT): \ 847 SymTab/$(am__dirstamp) SymTab/$(DEPDIR)/$(am__dirstamp) 848 SymTab/driver_cfa_cpp-TypeEquality.$(OBJEXT): SymTab/$(am__dirstamp) \ 849 SymTab/$(DEPDIR)/$(am__dirstamp) 843 850 SymTab/driver_cfa_cpp-Autogen.$(OBJEXT): SymTab/$(am__dirstamp) \ 844 851 SymTab/$(DEPDIR)/$(am__dirstamp) … … 1033 1040 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Po@am__quote@ 1034 1041 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-FixFunction.Po@am__quote@ 1042 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Po@am__quote@ 1035 1043 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Indexer.Po@am__quote@ 1036 1044 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Mangler.Po@am__quote@ 1045 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Po@am__quote@ 1037 1046 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Validate.Po@am__quote@ 1038 1047 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AddressExpr.Po@am__quote@ … … 2030 2039 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2031 2040 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-FixFunction.obj `if test -f 'SymTab/FixFunction.cc'; then $(CYGPATH_W) 'SymTab/FixFunction.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/FixFunction.cc'; fi` 2041 2042 SymTab/driver_cfa_cpp-ImplementationType.o: SymTab/ImplementationType.cc 2043 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-ImplementationType.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Tpo -c -o SymTab/driver_cfa_cpp-ImplementationType.o `test -f 'SymTab/ImplementationType.cc' || echo '$(srcdir)/'`SymTab/ImplementationType.cc 2044 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Po 2045 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SymTab/ImplementationType.cc' object='SymTab/driver_cfa_cpp-ImplementationType.o' libtool=no @AMDEPBACKSLASH@ 2046 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2047 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-ImplementationType.o `test -f 'SymTab/ImplementationType.cc' || echo '$(srcdir)/'`SymTab/ImplementationType.cc 2048 2049 SymTab/driver_cfa_cpp-ImplementationType.obj: SymTab/ImplementationType.cc 2050 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-ImplementationType.obj -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Tpo -c -o SymTab/driver_cfa_cpp-ImplementationType.obj `if test -f 'SymTab/ImplementationType.cc'; then $(CYGPATH_W) 'SymTab/ImplementationType.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/ImplementationType.cc'; fi` 2051 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Po 2052 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SymTab/ImplementationType.cc' object='SymTab/driver_cfa_cpp-ImplementationType.obj' libtool=no @AMDEPBACKSLASH@ 2053 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2054 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-ImplementationType.obj `if test -f 'SymTab/ImplementationType.cc'; then $(CYGPATH_W) 'SymTab/ImplementationType.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/ImplementationType.cc'; fi` 2055 2056 SymTab/driver_cfa_cpp-TypeEquality.o: SymTab/TypeEquality.cc 2057 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-TypeEquality.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Tpo -c -o SymTab/driver_cfa_cpp-TypeEquality.o `test -f 'SymTab/TypeEquality.cc' || echo '$(srcdir)/'`SymTab/TypeEquality.cc 2058 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Po 2059 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SymTab/TypeEquality.cc' object='SymTab/driver_cfa_cpp-TypeEquality.o' libtool=no @AMDEPBACKSLASH@ 2060 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2061 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-TypeEquality.o `test -f 'SymTab/TypeEquality.cc' || echo '$(srcdir)/'`SymTab/TypeEquality.cc 2062 2063 SymTab/driver_cfa_cpp-TypeEquality.obj: SymTab/TypeEquality.cc 2064 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-TypeEquality.obj -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Tpo -c -o SymTab/driver_cfa_cpp-TypeEquality.obj `if test -f 'SymTab/TypeEquality.cc'; then $(CYGPATH_W) 'SymTab/TypeEquality.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/TypeEquality.cc'; fi` 2065 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Po 2066 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SymTab/TypeEquality.cc' object='SymTab/driver_cfa_cpp-TypeEquality.obj' libtool=no @AMDEPBACKSLASH@ 2067 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2068 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-TypeEquality.obj `if test -f 'SymTab/TypeEquality.cc'; then $(CYGPATH_W) 'SymTab/TypeEquality.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/TypeEquality.cc'; fi` 2032 2069 2033 2070 SymTab/driver_cfa_cpp-Autogen.o: SymTab/Autogen.cc -
src/Parser/DeclarationNode.cc
rc13e8dc8 r9c35431 717 717 } 718 718 719 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body , StatementNode * with) {719 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body ) { 720 720 assert( type ); 721 721 assert( type->kind == TypeData::Function ); 722 722 assert( ! type->function.body ); 723 if ( with ) {724 // convert725 // void f(S s) with (s) { x = 0; }726 // to727 // void f(S s) { with(s) { x = 0; } }728 WithStmt * withStmt = strict_dynamic_cast< WithStmt * >( with->build() );729 withStmt->stmt = body->build();730 delete body;731 delete with;732 body = new StatementNode( new CompoundStmt( { withStmt } ) );733 }734 723 type->function.body = body; 735 724 return this; -
src/Parser/ParseNode.h
rc13e8dc8 r9c35431 69 69 70 70 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 71 virtual void printList( std::ostream &os, int indent = 0 ) const { 72 print( os, indent ); 73 if ( next ) next->print( os, indent ); 74 } 71 virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 75 72 76 73 static int indent_by; … … 123 120 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; } 124 121 125 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 126 os << expr.get() << std::endl; 127 } 122 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 128 123 void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 129 124 … … 262 257 DeclarationNode * addBitfield( ExpressionNode * size ); 263 258 DeclarationNode * addVarArgs(); 264 DeclarationNode * addFunctionBody( StatementNode * body , StatementNode * with = nullptr);259 DeclarationNode * addFunctionBody( StatementNode * body ); 265 260 DeclarationNode * addOldDeclList( DeclarationNode * list ); 266 261 DeclarationNode * setBase( TypeData * newType ); … … 364 359 virtual StatementNode * append_last_case( StatementNode * ); 365 360 366 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 367 os << stmt.get() << std::endl; 368 } 361 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 362 virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 369 363 private: 370 364 std::unique_ptr<Statement> stmt; … … 414 408 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ); 415 409 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when ); 416 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt );417 410 418 411 //############################################################################## -
src/Parser/StatementNode.cc
rc13e8dc8 r9c35431 37 37 DeclarationNode *agg = decl->extractAggregate(); 38 38 if ( agg ) { 39 StatementNode *nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );39 StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) ); 40 40 set_next( nextStmt ); 41 41 if ( decl->get_next() ) { … … 50 50 agg = decl; 51 51 } // if 52 stmt.reset( new DeclStmt( maybeMoveBuild< Declaration >(agg) ) );52 stmt.reset( new DeclStmt( noLabels, maybeMoveBuild< Declaration >(agg) ) ); 53 53 } // StatementNode::StatementNode 54 54 … … 75 75 76 76 if ( e ) 77 return new ExprStmt( e );77 return new ExprStmt( noLabels, e ); 78 78 else 79 return new NullStmt( );79 return new NullStmt( noLabels ); 80 80 } 81 81 … … 113 113 } 114 114 delete ctl; 115 return new IfStmt( cond, thenb, elseb, init );115 return new IfStmt( noLabels, cond, thenb, elseb, init ); 116 116 } 117 117 … … 120 120 buildMoveList< Statement, StatementNode >( stmt, branches ); 121 121 // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements 122 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches );122 return new SwitchStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches ); 123 123 } 124 124 Statement *build_case( ExpressionNode *ctl ) { 125 125 std::list< Statement * > branches; 126 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches );126 return new CaseStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches ); 127 127 } 128 128 Statement *build_default() { 129 129 std::list< Statement * > branches; 130 return new CaseStmt( n ullptr, branches, true );130 return new CaseStmt( noLabels, nullptr, branches, true ); 131 131 } 132 132 … … 135 135 buildMoveList< Statement, StatementNode >( stmt, branches ); 136 136 assert( branches.size() == 1 ); 137 return new WhileStmt( no tZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind );137 return new WhileStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind ); 138 138 } 139 139 … … 157 157 158 158 delete forctl; 159 return new ForStmt( init, cond, incr, branches.front() );159 return new ForStmt( noLabels, init, cond, incr, branches.front() ); 160 160 } 161 161 162 162 Statement *build_branch( BranchStmt::Type kind ) { 163 Statement * ret = new BranchStmt( "", kind );163 Statement * ret = new BranchStmt( noLabels, "", kind ); 164 164 return ret; 165 165 } 166 166 Statement *build_branch( std::string *identifier, BranchStmt::Type kind ) { 167 Statement * ret = new BranchStmt( *identifier, kind );167 Statement * ret = new BranchStmt( noLabels, *identifier, kind ); 168 168 delete identifier; // allocated by lexer 169 169 return ret; 170 170 } 171 171 Statement *build_computedgoto( ExpressionNode *ctl ) { 172 return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );172 return new BranchStmt( noLabels, maybeMoveBuild< Expression >(ctl), BranchStmt::Goto ); 173 173 } 174 174 … … 176 176 std::list< Expression * > exps; 177 177 buildMoveList( ctl, exps ); 178 return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr );178 return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr ); 179 179 } 180 180 … … 183 183 buildMoveList( ctl, exps ); 184 184 assertf( exps.size() < 2, "This means we are leaking memory"); 185 return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr );185 return new ThrowStmt( noLabels, ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr ); 186 186 } 187 187 … … 190 190 buildMoveList( ctl, exps ); 191 191 assertf( exps.size() < 2, "This means we are leaking memory"); 192 return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );192 return new ThrowStmt( noLabels, ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr ); 193 193 } 194 194 … … 204 204 CompoundStmt *tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt)); 205 205 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); 206 return new TryStmt( tryBlock, branches, finallyBlock );206 return new TryStmt( noLabels, tryBlock, branches, finallyBlock ); 207 207 } 208 208 Statement *build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ) { … … 210 210 buildMoveList< Statement, StatementNode >( body, branches ); 211 211 assert( branches.size() == 1 ); 212 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );212 return new CatchStmt( noLabels, kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() ); 213 213 } 214 214 Statement *build_finally( StatementNode *stmt ) { … … 216 216 buildMoveList< Statement, StatementNode >( stmt, branches ); 217 217 assert( branches.size() == 1 ); 218 return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) );218 return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt * >( branches.front() ) ); 219 219 } 220 220 … … 282 282 node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) ); 283 283 284 node->orelse.statement = maybeMoveBuild<Statement >( else_stmt );284 node->orelse.statement = maybeMoveBuild<Statement >( else_stmt ); 285 285 node->orelse.condition = notZeroExpr( maybeMoveBuild<Expression>( else_when ) ); 286 286 … … 288 288 } 289 289 290 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {291 std::list< Expression * > e;292 buildMoveList( exprs, e );293 Statement * s = maybeMoveBuild<Statement>( stmt );294 return new WithStmt( e, s );295 }296 297 290 Statement *build_compound( StatementNode *first ) { 298 CompoundStmt *cs = new CompoundStmt( );291 CompoundStmt *cs = new CompoundStmt( noLabels ); 299 292 buildMoveList( first, cs->get_kids() ); 300 293 return cs; … … 308 301 buildMoveList( input, in ); 309 302 buildMoveList( clobber, clob ); 310 return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );303 return new AsmStmt( noLabels, voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 311 304 } 312 305 -
src/Parser/parser.yy
rc13e8dc8 r9c35431 1058 1058 with_statement: 1059 1059 WITH '(' tuple_expression_list ')' statement 1060 { 1061 $$ = new StatementNode( build_with( $3, $5 ) ); 1062 } 1060 { throw SemanticError("With clause is currently unimplemented."); $$ = nullptr; } // FIX ME 1063 1061 ; 1064 1062 … … 2412 2410 { $$ = nullptr; } 2413 2411 | WITH '(' tuple_expression_list ')' 2414 { $$ = new StatementNode( build_with( $3, nullptr ) ); }2412 { throw SemanticError("With clause is currently unimplemented."); $$ = nullptr; } // FIX ME 2415 2413 ; 2416 2414 … … 2422 2420 // Add the function body to the last identifier in the function definition list, i.e., foo3: 2423 2421 // [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; } 2424 $1->get_last()->addFunctionBody( $3 , $2);2422 $1->get_last()->addFunctionBody( $3 ); 2425 2423 $$ = $1; 2426 2424 } … … 2430 2428 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2431 2429 typedefTable.leaveScope(); 2432 $$ = $2->addFunctionBody( $4 , $3)->addType( $1 );2430 $$ = $2->addFunctionBody( $4 )->addType( $1 ); 2433 2431 } 2434 2432 // handles default int return type, OBSOLESCENT (see 1) … … 2437 2435 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2438 2436 typedefTable.leaveScope(); 2439 $$ = $2->addFunctionBody( $4 , $3)->addQualifiers( $1 );2437 $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 ); 2440 2438 } 2441 2439 // handles default int return type, OBSOLESCENT (see 1) … … 2444 2442 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2445 2443 typedefTable.leaveScope(); 2446 $$ = $2->addFunctionBody( $4 , $3)->addQualifiers( $1 );2444 $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 ); 2447 2445 } 2448 2446 // handles default int return type, OBSOLESCENT (see 1) … … 2451 2449 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2452 2450 typedefTable.leaveScope(); 2453 $$ = $3->addFunctionBody( $5 , $4)->addQualifiers( $2 )->addQualifiers( $1 );2451 $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 ); 2454 2452 } 2455 2453 … … 2460 2458 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2461 2459 typedefTable.leaveScope(); 2462 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 , $4)->addType( $1 );2460 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 ); 2463 2461 } 2464 2462 // handles default int return type, OBSOLESCENT (see 1) … … 2467 2465 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2468 2466 typedefTable.leaveScope(); 2469 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 , $4)->addQualifiers( $1 );2467 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 ); 2470 2468 } 2471 2469 // handles default int return type, OBSOLESCENT (see 1) … … 2474 2472 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2475 2473 typedefTable.leaveScope(); 2476 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 , $4)->addQualifiers( $1 );2474 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 ); 2477 2475 } 2478 2476 // handles default int return type, OBSOLESCENT (see 1) … … 2481 2479 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2482 2480 typedefTable.leaveScope(); 2483 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 , $5)->addQualifiers( $2 )->addQualifiers( $1 );2481 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 ); 2484 2482 } 2485 2483 ; -
src/ResolvExpr/AlternativeFinder.cc
rc13e8dc8 r9c35431 83 83 } 84 84 85 void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt ) {86 Indenter indent = { Indenter::tabsize, indentAmt };87 for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) {88 i->print( os, indent );89 os << std::endl;90 }91 }92 93 85 namespace { 86 void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt = 0 ) { 87 Indenter indent = { Indenter::tabsize, indentAmt }; 88 for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) { 89 i->print( os, indent ); 90 os << std::endl; 91 } 92 } 93 94 94 void makeExprList( const AltList &in, std::list< Expression* > &out ) { 95 95 for ( AltList::const_iterator i = in.begin(); i != in.end(); ++i ) { … … 469 469 std::cerr << std::endl; 470 470 ) 471 std::list< SymTab::Indexer::IdData> candidates;471 std::list< DeclarationWithType* > candidates; 472 472 decls.lookupId( curDecl->get_name(), candidates ); 473 473 /// if ( candidates.empty() ) { std::cerr << "no candidates!" << std::endl; } 474 for ( const auto & data : candidates ) { 475 DeclarationWithType * candidate = data.id; 474 for ( std::list< DeclarationWithType* >::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate ) { 476 475 PRINT( 477 476 std::cerr << "inferRecursive: candidate is "; 478 candidate->print( std::cerr );477 (*candidate)->print( std::cerr ); 479 478 std::cerr << std::endl; 480 479 ) … … 483 482 TypeEnvironment newEnv( newAlt.env ); 484 483 OpenVarSet newOpenVars( openVars ); 485 Type *adjType = candidate->get_type()->clone();484 Type *adjType = (*candidate)->get_type()->clone(); 486 485 adjustExprType( adjType, newEnv, indexer ); 487 486 adjType->accept( global_renamer ); … … 501 500 Alternative newerAlt( newAlt ); 502 501 newerAlt.env = newEnv; 503 assertf( candidate->get_uniqueId(), "Assertion candidate does not have a unique ID: %s", toString( candidate ).c_str() ); 502 assertf( (*candidate)->get_uniqueId(), "Assertion candidate does not have a unique ID: %s", toString( *candidate ).c_str() ); 503 DeclarationWithType *candDecl = static_cast< DeclarationWithType* >( Declaration::declFromId( (*candidate)->get_uniqueId() ) ); 504 504 505 505 // everything with an empty idChain was pulled in by the current assertion. … … 516 516 // DOESN'T WORK: grandchild nodes conflict with their cousins 517 517 //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue; 518 Expression *varExpr = data.combine();518 Expression *varExpr = new VariableExpr( candDecl ); 519 519 delete varExpr->get_result(); 520 520 varExpr->set_result( adjType->clone() ); … … 522 522 std::cerr << "satisfying assertion " << curDecl->get_uniqueId() << " "; 523 523 curDecl->print( std::cerr ); 524 std::cerr << " with declaration " << candidate->get_uniqueId() << " ";525 candidate->print( std::cerr );524 std::cerr << " with declaration " << (*candidate)->get_uniqueId() << " "; 525 (*candidate)->print( std::cerr ); 526 526 std::cerr << std::endl; 527 527 ) … … 532 532 } 533 533 // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions 534 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr );534 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( (*candidate)->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr ); 535 535 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, /*newNeedParents,*/ level, indexer, out ); 536 536 } else { … … 1317 1317 1318 1318 void AlternativeFinder::visit( NameExpr *nameExpr ) { 1319 std::list< SymTab::Indexer::IdData> declList;1319 std::list< DeclarationWithType* > declList; 1320 1320 indexer.lookupId( nameExpr->get_name(), declList ); 1321 1321 PRINT( std::cerr << "nameExpr is " << nameExpr->get_name() << std::endl; ) 1322 for ( auto & data : declList ) { 1323 Expression * newExpr = data.combine(); 1324 // xxx - add in extra cost for with-statement exprs? 1325 alternatives.push_back( Alternative( newExpr, env, Cost::zero ) ); 1322 for ( std::list< DeclarationWithType* >::iterator i = declList.begin(); i != declList.end(); ++i ) { 1323 VariableExpr newExpr( *i ); 1324 alternatives.push_back( Alternative( newExpr.clone(), env, Cost::zero ) ); 1326 1325 PRINT( 1327 1326 std::cerr << "decl is "; 1328 data.id->print( std::cerr );1327 (*i)->print( std::cerr ); 1329 1328 std::cerr << std::endl; 1330 1329 std::cerr << "newExpr is "; 1331 newExpr ->print( std::cerr );1330 newExpr.print( std::cerr ); 1332 1331 std::cerr << std::endl; 1333 1332 ) … … 1421 1420 } 1422 1421 1423 namespace { 1424 void resolveAttr( SymTab::Indexer::IdData data, FunctionType *function, Type *argType, const TypeEnvironment &env, AlternativeFinder & finder ) { 1425 // assume no polymorphism 1426 // assume no implicit conversions 1427 assert( function->get_parameters().size() == 1 ); 1428 PRINT( 1429 std::cerr << "resolvAttr: funcDecl is "; 1430 data.id->print( std::cerr ); 1431 std::cerr << " argType is "; 1432 argType->print( std::cerr ); 1433 std::cerr << std::endl; 1434 ) 1435 const SymTab::Indexer & indexer = finder.get_indexer(); 1436 AltList & alternatives = finder.get_alternatives(); 1437 if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) { 1438 alternatives.push_back( Alternative( new AttrExpr( data.combine(), argType->clone() ), env, Cost::zero ) ); 1439 for ( DeclarationWithType * retVal : function->returnVals ) { 1440 alternatives.back().expr->result = retVal->get_type()->clone(); 1441 } // for 1442 } // if 1443 } 1422 void AlternativeFinder::resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ) { 1423 // assume no polymorphism 1424 // assume no implicit conversions 1425 assert( function->get_parameters().size() == 1 ); 1426 PRINT( 1427 std::cerr << "resolvAttr: funcDecl is "; 1428 funcDecl->print( std::cerr ); 1429 std::cerr << " argType is "; 1430 argType->print( std::cerr ); 1431 std::cerr << std::endl; 1432 ) 1433 if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) { 1434 alternatives.push_back( Alternative( new AttrExpr( new VariableExpr( funcDecl ), argType->clone() ), env, Cost::zero ) ); 1435 for ( std::list< DeclarationWithType* >::iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) { 1436 alternatives.back().expr->set_result( (*i)->get_type()->clone() ); 1437 } // for 1438 } // if 1444 1439 } 1445 1440 … … 1448 1443 NameExpr *nameExpr = dynamic_cast< NameExpr* >( attrExpr->get_attr() ); 1449 1444 assert( nameExpr ); 1450 std::list< SymTab::Indexer::IdData> attrList;1445 std::list< DeclarationWithType* > attrList; 1451 1446 indexer.lookupId( nameExpr->get_name(), attrList ); 1452 1447 if ( attrExpr->get_isType() || attrExpr->get_expr() ) { 1453 for ( auto & data : attrList ) { 1454 DeclarationWithType * id = data.id; 1448 for ( std::list< DeclarationWithType* >::iterator i = attrList.begin(); i != attrList.end(); ++i ) { 1455 1449 // check if the type is function 1456 if ( FunctionType *function = dynamic_cast< FunctionType* >( id->get_type() ) ) {1450 if ( FunctionType *function = dynamic_cast< FunctionType* >( (*i)->get_type() ) ) { 1457 1451 // assume exactly one parameter 1458 1452 if ( function->get_parameters().size() == 1 ) { 1459 1453 if ( attrExpr->get_isType() ) { 1460 resolveAttr( data, function, attrExpr->get_type(), env, *this);1454 resolveAttr( *i, function, attrExpr->get_type(), env ); 1461 1455 } else { 1462 1456 AlternativeFinder finder( indexer, env ); … … 1464 1458 for ( AltList::iterator choice = finder.alternatives.begin(); choice != finder.alternatives.end(); ++choice ) { 1465 1459 if ( choice->expr->get_result()->size() == 1 ) { 1466 resolveAttr( data, function, choice->expr->get_result(), choice->env, *this);1460 resolveAttr(*i, function, choice->expr->get_result(), choice->env ); 1467 1461 } // fi 1468 1462 } // for … … 1472 1466 } // for 1473 1467 } else { 1474 for ( auto & data : attrList ) { 1475 alternatives.push_back( Alternative( data.combine(), env, Cost::zero ) ); 1468 for ( std::list< DeclarationWithType* >::iterator i = attrList.begin(); i != attrList.end(); ++i ) { 1469 VariableExpr newExpr( *i ); 1470 alternatives.push_back( Alternative( newExpr.clone(), env, Cost::zero ) ); 1476 1471 renameTypes( alternatives.back().expr ); 1477 1472 } // for -
src/ResolvExpr/AlternativeFinder.h
rc13e8dc8 r9c35431 142 142 template< typename OutputIterator > 143 143 void inferParameters( const AssertionSet &need, AssertionSet &have, const Alternative &newAlt, OpenVarSet &openVars, OutputIterator out ); 144 void resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ); 144 145 145 146 const SymTab::Indexer &indexer; … … 150 151 151 152 Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer, TypeEnvironment &env ); 153 void referenceToRvalueConversion( Expression *& expr ); 152 154 153 155 template< typename InputIterator, typename OutputIterator > … … 172 174 173 175 Cost sumCost( const AltList &in ); 174 void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt = 0 );175 176 176 177 template< typename InputIterator > … … 180 181 } 181 182 } 182 183 183 } // namespace ResolvExpr 184 184 -
src/ResolvExpr/Resolver.cc
rc13e8dc8 r9c35431 26 26 #include "Common/utility.h" // for ValueGuard, group_iterate 27 27 #include "CurrentObject.h" // for CurrentObject 28 #include "InitTweak/GenInit.h"29 28 #include "InitTweak/InitTweak.h" // for isIntrinsicSingleArgCallStmt 30 29 #include "RenameVars.h" // for RenameVars, global_renamer … … 41 40 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution 42 41 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept 43 #include "Tuples/Tuples.h"44 42 #include "typeops.h" // for extractResultType 45 43 #include "Unify.h" // for unify … … 48 46 49 47 namespace ResolvExpr { 50 struct Resolver final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver>, public WithShortCircuiting , public WithStmtsToAdd{48 struct Resolver final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver>, public WithShortCircuiting { 51 49 Resolver() {} 52 50 Resolver( const SymTab::Indexer & other ) { … … 76 74 void previsit( CatchStmt *catchStmt ); 77 75 void previsit( WaitForStmt * stmt ); 78 void previsit( WithStmt * withStmt );79 76 80 77 void previsit( SingleInit *singleInit ); … … 372 369 if ( throwStmt->get_expr() ) { 373 370 StructDecl * exception_decl = 374 indexer.lookupStruct( "__cfa abi_ehm__base_exception_t" );371 indexer.lookupStruct( "__cfaehm__base_exception_t" ); 375 372 assert( exception_decl ); 376 373 Type * exceptType = new PointerType( noQualifiers, new StructInstType( noQualifiers, exception_decl ) ); … … 571 568 findSingleExpression( stmt->orelse.condition, this->indexer ); 572 569 stmt->orelse.statement->accept( *visitor ); 573 }574 }575 576 bool isStructOrUnion( Type * t ) {577 t = t->stripReferences();578 return dynamic_cast< StructInstType * >( t ) || dynamic_cast< UnionInstType * >( t );579 }580 581 void Resolver::previsit( WithStmt * withStmt ) {582 for ( Expression *& expr : withStmt->exprs ) {583 TypeEnvironment env;584 AlternativeFinder finder( indexer, env );585 finder.findWithAdjustment( expr );586 587 // only struct- and union-typed expressions are viable candidates588 AltList candidates;589 for ( Alternative & alt : finder.get_alternatives() ) {590 if ( isStructOrUnion( alt.expr->result ) ) {591 candidates.push_back( std::move( alt ) );592 }593 }594 595 // choose the lowest cost expression among the candidates596 AltList winners;597 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) );598 if ( winners.size() == 0 ) {599 throw SemanticError( "No reasonable alternatives for with statement expression: ", expr );600 } else if ( winners.size() != 1 ) {601 std::ostringstream stream;602 stream << "Cannot choose between " << winners.size() << " alternatives for with statement expression\n";603 expr->print( stream );604 stream << "Alternatives are:\n";605 printAlts( winners, stream, 1 );606 throw SemanticError( stream.str() );607 }608 609 // there is one unambiguous interpretation - move the expression into the with statement610 Alternative & alt = winners.front();611 finishExpr( alt.expr, alt.env, expr->env );612 delete expr;613 expr = alt.expr;614 alt.expr = nullptr;615 616 // if with expression might be impure, create a temporary so that it is evaluated once617 if ( Tuples::maybeImpure( expr ) ) {618 static UniqueName tmpNamer( "_with_tmp_" );619 ObjectDecl * tmp = ObjectDecl::newObject( tmpNamer.newName(), expr->result->clone(), new SingleInit( expr ) );620 expr = new VariableExpr( tmp );621 stmtsToAddBefore.push_back( new DeclStmt( tmp ) );622 if ( InitTweak::isConstructable( tmp->type ) ) {623 // generate ctor/dtor and resolve them624 tmp->init = InitTweak::genCtorInit( tmp );625 tmp->accept( *visitor );626 }627 }628 570 } 629 571 } -
src/ResolvExpr/typeops.h
rc13e8dc8 r9c35431 102 102 bool occurs( Type *type, std::string varName, const TypeEnvironment &env ); 103 103 104 // in AlternativeFinder.cc105 void referenceToRvalueConversion( Expression *& expr );106 107 104 // flatten tuple type into list of types 108 105 template< typename OutputIterator > -
src/SymTab/AddVisit.h
rc13e8dc8 r9c35431 24 24 // add any new declarations after the previous statement 25 25 for ( std::list< Declaration* >::iterator decl = visitor.declsToAddAfter.begin(); decl != visitor.declsToAddAfter.end(); ++decl ) { 26 DeclStmt *declStmt = new DeclStmt( *decl );26 DeclStmt *declStmt = new DeclStmt( noLabels, *decl ); 27 27 stmts.insert( stmt, declStmt ); 28 28 } … … 36 36 // add any new declarations before the statement 37 37 for ( std::list< Declaration* >::iterator decl = visitor.declsToAdd.begin(); decl != visitor.declsToAdd.end(); ++decl ) { 38 DeclStmt *declStmt = new DeclStmt( *decl );38 DeclStmt *declStmt = new DeclStmt( noLabels, *decl ); 39 39 stmts.insert( stmt, declStmt ); 40 40 } -
src/SymTab/Autogen.cc
rc13e8dc8 r9c35431 267 267 Type::StorageClasses scs = functionNesting > 0 ? Type::StorageClasses() : Type::StorageClasses( Type::Static ); 268 268 LinkageSpec::Spec spec = isIntrinsic ? LinkageSpec::Intrinsic : LinkageSpec::AutoGen; 269 FunctionDecl * decl = new FunctionDecl( fname, scs, spec, ftype, new CompoundStmt( ),269 FunctionDecl * decl = new FunctionDecl( fname, scs, spec, ftype, new CompoundStmt( noLabels ), 270 270 std::list< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ); 271 271 decl->fixUniqueId(); … … 302 302 assert( assignType->returnVals.size() == 1 ); 303 303 ObjectDecl * dstParam = strict_dynamic_cast< ObjectDecl * >( assignType->parameters.front() ); 304 dcl->statements->push_back( new ReturnStmt( n ew VariableExpr( dstParam ) ) );304 dcl->statements->push_back( new ReturnStmt( noLabels, new VariableExpr( dstParam ) ) ); 305 305 } 306 306 resolve( dcl ); … … 471 471 copy->args.push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 472 472 copy->args.push_back( new SizeofExpr( srcParam->get_type()->clone() ) ); 473 *out++ = new ExprStmt( copy );473 *out++ = new ExprStmt( noLabels, copy ); 474 474 } 475 475 … … 547 547 callExpr->get_args().push_back( new VariableExpr( dstParam ) ); 548 548 callExpr->get_args().push_back( new VariableExpr( srcParam ) ); 549 funcDecl->statements->push_back( new ExprStmt( callExpr ) );549 funcDecl->statements->push_back( new ExprStmt( noLabels, callExpr ) ); 550 550 } else { 551 551 // default ctor/dtor body is empty - add unused attribute to parameter to silence warnings … … 572 572 expr->args.push_back( new CastExpr( new VariableExpr( dst ), new ReferenceType( Type::Qualifiers(), typeDecl->base->clone() ) ) ); 573 573 if ( src ) expr->args.push_back( new CastExpr( new VariableExpr( src ), typeDecl->base->clone() ) ); 574 dcl->statements->kids.push_back( new ExprStmt( expr ) );574 dcl->statements->kids.push_back( new ExprStmt( noLabels, expr ) ); 575 575 }; 576 576 … … 667 667 untyped->get_args().push_back( new VariableExpr( ftype->get_parameters().back() ) ); 668 668 } 669 function->get_statements()->get_kids().push_back( new ExprStmt( untyped ) );670 function->get_statements()->get_kids().push_back( new ReturnStmt( UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) );669 function->get_statements()->get_kids().push_back( new ExprStmt( noLabels, untyped ) ); 670 function->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) ); 671 671 } 672 672 -
src/SymTab/Autogen.h
rc13e8dc8 r9c35431 107 107 fExpr->args.splice( fExpr->args.end(), args ); 108 108 109 *out++ = new ExprStmt( fExpr );109 *out++ = new ExprStmt( noLabels, fExpr ); 110 110 111 111 srcParam.clearArrayIndices(); … … 165 165 166 166 // for stmt's body, eventually containing call 167 CompoundStmt * body = new CompoundStmt( );167 CompoundStmt * body = new CompoundStmt( noLabels ); 168 168 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->kids ), array->base, addCast, forward ); 169 169 170 170 // block containing for stmt and index variable 171 171 std::list<Statement *> initList; 172 CompoundStmt * block = new CompoundStmt( );173 block->push_back( new DeclStmt( index ) );172 CompoundStmt * block = new CompoundStmt( noLabels ); 173 block->push_back( new DeclStmt( noLabels, index ) ); 174 174 if ( listInit ) block->get_kids().push_back( listInit ); 175 block->push_back( new ForStmt( initList, cond, inc, body ) );175 block->push_back( new ForStmt( noLabels, initList, cond, inc, body ) ); 176 176 177 177 *out++ = block; -
src/SymTab/Indexer.cc
rc13e8dc8 r9c35431 40 40 41 41 namespace SymTab { 42 std::ostream & operator<<( std::ostream & out, const Indexer::IdData & data ) { 43 return out << "(" << data.id << "," << data.baseExpr << ")"; 44 } 45 46 typedef std::unordered_map< std::string, Indexer::IdData > MangleTable; 42 typedef std::unordered_map< std::string, DeclarationWithType* > MangleTable; 47 43 typedef std::unordered_map< std::string, MangleTable > IdTable; 48 44 typedef std::unordered_map< std::string, NamedTypeDecl* > TypeTable; … … 101 97 } 102 98 103 void Indexer::removeSpecialOverrides( const std::string &id, std::list< IdData> & out ) const {99 void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const { 104 100 // only need to perform this step for constructors, destructors, and assignment functions 105 101 if ( ! CodeGen::isCtorDtorAssign( id ) ) return; … … 108 104 struct ValueType { 109 105 struct DeclBall { 110 IdDatadecl;106 FunctionDecl * decl; 111 107 bool isUserDefinedFunc; // properties for this particular decl 112 108 bool isDefaultCtor; … … 124 120 // another FunctionDecl for the current type was found - determine 125 121 // if it has special properties and update data structure accordingly 126 ValueType & operator+=( IdData data ) { 127 DeclarationWithType * function = data.id; 122 ValueType & operator+=( FunctionDecl * function ) { 128 123 bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() ); 129 124 bool isDefaultCtor = InitTweak::isDefaultConstructor( function ); 130 125 bool isDtor = InitTweak::isDestructor( function ); 131 126 bool isCopyFunc = InitTweak::isCopyFunction( function, function->get_name() ); 132 decls.push_back( DeclBall{ data, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } );127 decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } ); 133 128 existsUserDefinedFunc = existsUserDefinedFunc || isUserDefinedFunc; 134 129 existsUserDefinedCtor = existsUserDefinedCtor || (isUserDefinedFunc && CodeGen::isConstructor( function->get_name() ) ); … … 140 135 }; // ValueType 141 136 142 std::list< IdData> copy;137 std::list< DeclarationWithType * > copy; 143 138 copy.splice( copy.end(), out ); 144 139 145 140 // organize discovered declarations by type 146 141 std::unordered_map< std::string, ValueType > funcMap; 147 for ( autodecl : copy ) {148 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl .id) ) {142 for ( DeclarationWithType * decl : copy ) { 143 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ) ) { 149 144 std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters(); 150 145 assert( ! params.empty() ); … … 152 147 Type * base = InitTweak::getPointerBase( params.front()->get_type() ); 153 148 assert( base ); 154 funcMap[ Mangler::mangle( base ) ] += decl;149 funcMap[ Mangler::mangle( base ) ] += function; 155 150 } else { 156 151 out.push_back( decl ); … … 169 164 bool noUserDefinedFunc = ! val.existsUserDefinedFunc; 170 165 bool isUserDefinedFunc = ball.isUserDefinedFunc; 171 bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl .id->get_linkage() == LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides166 bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl->get_linkage() == LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides 172 167 bool isAcceptableCopyFunc = ! val.existsUserDefinedCopyFunc && ball.isCopyFunc; // handles copy ctor and assignment operator 173 168 bool isAcceptableDtor = ! val.existsUserDefinedDtor && ball.isDtor; … … 224 219 } 225 220 226 void Indexer::lookupId( const std::string &id, std::list< IdData> &out ) const {221 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const { 227 222 std::unordered_set< std::string > foundMangleNames; 228 223 … … 294 289 const MangleTable &mangleTable = decls->second; 295 290 MangleTable::const_iterator decl = mangleTable.find( mangleName ); 296 if ( decl != mangleTable.end() ) return decl->second .id;291 if ( decl != mangleTable.end() ) return decl->second; 297 292 } 298 293 … … 309 304 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 310 305 // check for C decls with the same name, skipping those with a compatible type (by mangleName) 311 if ( ! LinkageSpec::isMangled( decl->second .id->get_linkage() ) && decl->first != mangleName ) return true;306 if ( ! LinkageSpec::isMangled( decl->second->get_linkage() ) && decl->first != mangleName ) return true; 312 307 } 313 308 } … … 326 321 // check for C decls with the same name, skipping 327 322 // those with an incompatible type (by mangleName) 328 if ( ! LinkageSpec::isMangled( decl->second .id->get_linkage() ) && decl->first == mangleName ) return true;323 if ( ! LinkageSpec::isMangled( decl->second->get_linkage() ) && decl->first == mangleName ) return true; 329 324 } 330 325 } … … 408 403 } 409 404 410 void Indexer::addId( DeclarationWithType *decl , Expression * baseExpr) {405 void Indexer::addId( DeclarationWithType *decl ) { 411 406 debugPrint( "Adding Id " << decl->name << std::endl ); 412 407 makeWritable(); … … 444 439 445 440 // add to indexer 446 tables->idTable[ name ][ mangleName ] = { decl, baseExpr };441 tables->idTable[ name ][ mangleName ] = decl; 447 442 ++tables->size; 448 443 } … … 568 563 if ( ! addedDeclConflicts( existing->second, decl ) ) { 569 564 existing->second = decl; 570 }571 }572 }573 574 void Indexer::addWith( WithStmt * stmt ) {575 for ( Expression * expr : stmt->exprs ) {576 if ( expr->result ) {577 AggregateDecl * aggr = expr->result->stripReferences()->getAggr();578 assertf( aggr, "WithStmt expr has non-aggregate type: %s", toString( expr->result ).c_str() );579 580 for ( Declaration * decl : aggr->members ) {581 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {582 addId( dwt, expr );583 }584 }585 565 } 586 566 } … … 665 645 666 646 } 667 668 Expression * Indexer::IdData::combine() const {669 if ( baseExpr ) {670 Expression * base = baseExpr->clone();671 ResolvExpr::referenceToRvalueConversion( base );672 Expression * ret = new MemberExpr( id, base );673 // xxx - this introduces hidden environments, for now remove them.674 // std::swap( base->env, ret->env );675 delete base->env;676 base->env = nullptr;677 return ret;678 } else {679 return new VariableExpr( id );680 }681 }682 647 } // namespace SymTab 683 648 -
src/SymTab/Indexer.h
rc13e8dc8 r9c35431 39 39 void leaveScope(); 40 40 41 struct IdData {42 DeclarationWithType * id;43 Expression * baseExpr; // WithExpr44 45 Expression * combine() const;46 };47 48 41 /// Gets all declarations with the given ID 49 void lookupId( const std::string &id, std::list< IdData> &out ) const;42 void lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const; 50 43 /// Gets the top-most type declaration with the given ID 51 44 NamedTypeDecl *lookupType( const std::string &id ) const; … … 74 67 TraitDecl *lookupTraitAtScope( const std::string &id, unsigned long scope ) const; 75 68 76 void addId( DeclarationWithType *decl , Expression * baseExpr = nullptr);69 void addId( DeclarationWithType *decl ); 77 70 void addType( NamedTypeDecl *decl ); 78 71 void addStruct( const std::string &id ); … … 82 75 void addUnion( UnionDecl *decl ); 83 76 void addTrait( TraitDecl *decl ); 84 85 /// adds all of the IDs from WithStmt exprs86 void addWith( WithStmt * );87 77 88 78 /// convenience function for adding a list of Ids to the indexer … … 110 100 // so that they will not be selected 111 101 // void removeSpecialOverrides( FunctionDecl *decl ); 112 void removeSpecialOverrides( const std::string &id, std::list< IdData> & out ) const;102 void removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const; 113 103 114 104 /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope) -
src/SymTab/Validate.cc
rc13e8dc8 r9c35431 81 81 82 82 namespace SymTab { 83 struct HoistStruct final : public WithDeclsToAdd, public WithGuards { 83 class HoistStruct final : public Visitor { 84 template< typename Visitor > 85 friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ); 86 template< typename Visitor > 87 friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ); 88 public: 84 89 /// Flattens nested struct types 85 90 static void hoistStruct( std::list< Declaration * > &translationUnit ); 86 91 87 void previsit( EnumInstType * enumInstType ); 88 void previsit( StructInstType * structInstType ); 89 void previsit( UnionInstType * unionInstType ); 90 void previsit( StructDecl * aggregateDecl ); 91 void previsit( UnionDecl * aggregateDecl ); 92 92 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 93 94 virtual void visit( EnumInstType *enumInstType ); 95 virtual void visit( StructInstType *structInstType ); 96 virtual void visit( UnionInstType *unionInstType ); 97 virtual void visit( StructDecl *aggregateDecl ); 98 virtual void visit( UnionDecl *aggregateDecl ); 99 100 virtual void visit( CompoundStmt *compoundStmt ); 101 virtual void visit( SwitchStmt *switchStmt ); 93 102 private: 103 HoistStruct(); 104 94 105 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl ); 95 106 96 bool inStruct = false; 107 std::list< Declaration * > declsToAdd, declsToAddAfter; 108 bool inStruct; 97 109 }; 98 110 … … 293 305 294 306 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 295 PassVisitor<HoistStruct> hoister; 296 acceptAll( translationUnit, hoister ); 307 HoistStruct hoister; 308 acceptAndAdd( translationUnit, hoister ); 309 } 310 311 HoistStruct::HoistStruct() : inStruct( false ) { 297 312 } 298 313 … … 305 320 if ( inStruct ) { 306 321 // Add elements in stack order corresponding to nesting structure. 307 declsToAddBefore.push_front( aggregateDecl ); 322 declsToAdd.push_front( aggregateDecl ); 323 Visitor::visit( aggregateDecl ); 308 324 } else { 309 GuardValue( inStruct );310 325 inStruct = true; 326 Visitor::visit( aggregateDecl ); 327 inStruct = false; 311 328 } // if 312 329 // Always remove the hoisted aggregate from the inner structure. 313 GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, isStructOrUnion, false ); });314 } 315 316 void HoistStruct:: previsit( EnumInstType * inst) {317 if ( inst->baseEnum) {318 declsToAdd Before.push_front( inst->baseEnum);319 } 320 } 321 322 void HoistStruct:: previsit( StructInstType * inst) {323 if ( inst->baseStruct) {324 declsToAdd Before.push_front( inst->baseStruct);325 } 326 } 327 328 void HoistStruct:: previsit( UnionInstType * inst) {329 if ( inst->baseUnion) {330 declsToAdd Before.push_front( inst->baseUnion);331 } 332 } 333 334 void HoistStruct:: previsit( StructDecl *aggregateDecl ) {330 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 331 } 332 333 void HoistStruct::visit( EnumInstType *structInstType ) { 334 if ( structInstType->get_baseEnum() ) { 335 declsToAdd.push_front( structInstType->get_baseEnum() ); 336 } 337 } 338 339 void HoistStruct::visit( StructInstType *structInstType ) { 340 if ( structInstType->get_baseStruct() ) { 341 declsToAdd.push_front( structInstType->get_baseStruct() ); 342 } 343 } 344 345 void HoistStruct::visit( UnionInstType *structInstType ) { 346 if ( structInstType->get_baseUnion() ) { 347 declsToAdd.push_front( structInstType->get_baseUnion() ); 348 } 349 } 350 351 void HoistStruct::visit( StructDecl *aggregateDecl ) { 335 352 handleAggregate( aggregateDecl ); 336 353 } 337 354 338 void HoistStruct:: previsit( UnionDecl *aggregateDecl ) {355 void HoistStruct::visit( UnionDecl *aggregateDecl ) { 339 356 handleAggregate( aggregateDecl ); 357 } 358 359 void HoistStruct::visit( CompoundStmt *compoundStmt ) { 360 addVisit( compoundStmt, *this ); 361 } 362 363 void HoistStruct::visit( SwitchStmt *switchStmt ) { 364 addVisit( switchStmt, *this ); 340 365 } 341 366 -
src/SymTab/module.mk
rc13e8dc8 r9c35431 19 19 SymTab/Validate.cc \ 20 20 SymTab/FixFunction.cc \ 21 SymTab/ImplementationType.cc \ 22 SymTab/TypeEquality.cc \ 21 23 SymTab/Autogen.cc -
src/SynTree/CompoundStmt.cc
rc13e8dc8 r9c35431 28 28 using std::endl; 29 29 30 CompoundStmt::CompoundStmt( ) : Statement() {30 CompoundStmt::CompoundStmt( std::list<Label> labels ) : Statement( labels ) { 31 31 } 32 32 33 CompoundStmt::CompoundStmt( std::list<Statement *> stmts ) : Statement( ), kids( stmts ) {33 CompoundStmt::CompoundStmt( std::list<Statement *> stmts ) : Statement( noLabels ), kids( stmts ) { 34 34 } 35 35 -
src/SynTree/DeclStmt.cc
rc13e8dc8 r9c35431 23 23 #include "SynTree/Label.h" // for Label 24 24 25 DeclStmt::DeclStmt( Declaration *decl ) : Statement(), decl( decl ) {25 DeclStmt::DeclStmt( std::list<Label> labels, Declaration *decl ) : Statement( labels ), decl( decl ) { 26 26 } 27 27 -
src/SynTree/Mutator.cc
rc13e8dc8 r9c35431 203 203 } 204 204 205 Statement * Mutator::mutate( WithStmt * withStmt ) {206 mutateAll( withStmt->exprs, *this );207 withStmt->stmt = maybeMutate( withStmt->stmt, *this );208 return withStmt;209 }210 211 205 NullStmt * Mutator::mutate( NullStmt *nullStmt ) { 212 206 return nullStmt; -
src/SynTree/Mutator.h
rc13e8dc8 r9c35431 50 50 virtual Statement * mutate( FinallyStmt * catchStmt ); 51 51 virtual Statement * mutate( WaitForStmt * waitforStmt ); 52 virtual Statement * mutate( WithStmt * withStmt );53 52 virtual NullStmt * mutate( NullStmt * nullStmt ); 54 53 virtual Statement * mutate( DeclStmt * declStmt ); -
src/SynTree/ReferenceToType.cc
rc13e8dc8 r9c35431 70 70 bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; } 71 71 72 AggregateDecl * StructInstType::getAggr() { return baseStruct; }73 74 72 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 75 73 assert( baseStruct ); … … 103 101 104 102 bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; } 105 106 AggregateDecl * UnionInstType::getAggr() { return baseUnion; }107 103 108 104 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { -
src/SynTree/Statement.cc
rc13e8dc8 r9c35431 32 32 using std::endl; 33 33 34 Statement::Statement( const std::list<Label> &labels ) : labels( labels ) {}34 Statement::Statement( std::list<Label> labels ) : labels( labels ) {} 35 35 36 36 void Statement::print( std::ostream & os, Indenter ) const { … … 46 46 Statement::~Statement() {} 47 47 48 ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {}48 ExprStmt::ExprStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {} 49 49 50 50 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} … … 60 60 61 61 62 AsmStmt::AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}62 AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {} 63 63 64 64 AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) { … … 96 96 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 97 97 98 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticError ) :99 Statement( ), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) {98 BranchStmt::BranchStmt( std::list<Label> labels, Label target, Type type ) throw ( SemanticError ) : 99 Statement( labels ), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) { 100 100 //actually this is a syntactic error signaled by the parser 101 101 if ( type == BranchStmt::Goto && target.empty() ) { … … 104 104 } 105 105 106 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticError ) :107 Statement( ), computedTarget( computedTarget ), type( type ) {106 BranchStmt::BranchStmt( std::list<Label> labels, Expression *computedTarget, Type type ) throw ( SemanticError ) : 107 Statement( labels ), computedTarget( computedTarget ), type( type ) { 108 108 if ( type != BranchStmt::Goto || computedTarget == nullptr ) { 109 109 throw SemanticError("Computed target not valid in branch statement"); … … 118 118 } 119 119 120 ReturnStmt::ReturnStmt( Expression *expr ) : Statement(), expr( expr ) {}120 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {} 121 121 122 122 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} … … 135 135 } 136 136 137 IfStmt::IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):138 Statement( ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}137 IfStmt::IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ): 138 Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {} 139 139 140 140 IfStmt::IfStmt( const IfStmt & other ) : … … 176 176 } 177 177 178 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> &statements ):179 Statement( ), condition( condition ), statements( statements ) {178 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, const std::list<Statement *> &statements ): 179 Statement( labels ), condition( condition ), statements( statements ) { 180 180 } 181 181 … … 201 201 } 202 202 203 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :204 Statement( ), condition( condition ), stmts( statements ), _isDefault( deflt ) {203 CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) : 204 Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) { 205 205 if ( isDefault() && condition != 0 ) throw SemanticError("default case with condition: ", condition); 206 206 } … … 216 216 } 217 217 218 CaseStmt * CaseStmt::makeDefault( const std::list<Label> & labels, std::list<Statement *> stmts ) { 219 CaseStmt * stmt = new CaseStmt( nullptr, stmts, true ); 220 stmt->labels = labels; 221 return stmt; 218 CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) { 219 return new CaseStmt( labels, 0, stmts, true ); 222 220 } 223 221 … … 235 233 } 236 234 237 WhileStmt::WhileStmt( Expression *condition, Statement *body, bool isDoWhile ):238 Statement( ), condition( condition), body( body), isDoWhile( isDoWhile) {235 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ): 236 Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) { 239 237 } 240 238 … … 257 255 } 258 256 259 ForStmt::ForStmt( std::list< Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):260 Statement( ), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {257 ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ): 258 Statement( labels ), initialization( initialization ), condition( condition ), increment( increment ), body( body ) { 261 259 } 262 260 … … 304 302 } 305 303 306 ThrowStmt::ThrowStmt( Kind kind, Expression * expr, Expression * target ) :307 Statement( ), kind(kind), expr(expr), target(target) {304 ThrowStmt::ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target ) : 305 Statement( labels ), kind(kind), expr(expr), target(target) { 308 306 assertf(Resume == kind || nullptr == target, "Non-local termination throw is not accepted." ); 309 307 } … … 328 326 } 329 327 330 TryStmt::TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :331 Statement( ), block( tryBlock ), handlers( handlers ), finallyBlock( finallyBlock ) {328 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) : 329 Statement( labels ), block( tryBlock ), handlers( handlers ), finallyBlock( finallyBlock ) { 332 330 } 333 331 … … 361 359 } 362 360 363 CatchStmt::CatchStmt( Kind kind, Declaration *decl, Expression *cond, Statement *body ) :364 Statement( ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {361 CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) : 362 Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { 365 363 assertf( decl, "Catch clause must have a declaration." ); 366 364 } … … 393 391 394 392 395 FinallyStmt::FinallyStmt( CompoundStmt *block ) : Statement(), block( block ) { 393 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) { 394 assert( labels.empty() ); // finally statement cannot be labeled 396 395 } 397 396 … … 409 408 } 410 409 411 WaitForStmt::WaitForStmt( ) : Statement() {410 WaitForStmt::WaitForStmt( std::list<Label> labels ) : Statement( labels ) { 412 411 timeout.time = nullptr; 413 412 timeout.statement = nullptr; … … 456 455 } 457 456 458 459 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Statement(), exprs( exprs ), stmt( stmt ) {} 460 WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) { 461 cloneAll( other.exprs, exprs ); 462 } 463 WithStmt::~WithStmt() { 464 deleteAll( exprs ); 465 delete stmt; 466 } 467 468 void WithStmt::print( std::ostream & os, Indenter indent ) const { 469 os << "With statement" << endl; 470 os << indent << "... with statement:" << endl << indent+1; 471 stmt->print( os, indent+1 ); 472 } 473 474 475 NullStmt::NullStmt( const std::list<Label> & labels ) : Statement( labels ) { 476 } 457 NullStmt::NullStmt( std::list<Label> labels ) : Statement( labels ) {} 458 NullStmt::NullStmt() : Statement( std::list<Label>() ) {} 477 459 478 460 void NullStmt::print( std::ostream &os, Indenter ) const { … … 480 462 } 481 463 482 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( ), callStmt( callStmt ) {464 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) { 483 465 assert( callStmt ); 484 466 } -
src/SynTree/Statement.h
rc13e8dc8 r9c35431 37 37 std::list<Label> labels; 38 38 39 Statement( const std::list<Label> & labels = {});39 Statement( std::list<Label> labels ); 40 40 virtual ~Statement(); 41 41 … … 53 53 std::list<Statement*> kids; 54 54 55 CompoundStmt( );55 CompoundStmt( std::list<Label> labels ); 56 56 CompoundStmt( std::list<Statement *> stmts ); 57 57 CompoundStmt( const CompoundStmt &other ); … … 70 70 class NullStmt : public Statement { 71 71 public: 72 NullStmt( const std::list<Label> & labels = {} ); 72 NullStmt(); 73 NullStmt( std::list<Label> labels ); 73 74 74 75 virtual NullStmt *clone() const override { return new NullStmt( *this ); } … … 82 83 Expression *expr; 83 84 84 ExprStmt( Expression *expr );85 ExprStmt( std::list<Label> labels, Expression *expr ); 85 86 ExprStmt( const ExprStmt &other ); 86 87 virtual ~ExprStmt(); … … 103 104 std::list<Label> gotolabels; 104 105 105 AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );106 AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ); 106 107 AsmStmt( const AsmStmt &other ); 107 108 virtual ~AsmStmt(); … … 133 134 std::list<Statement *> initialization; 134 135 135 IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart,136 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, 136 137 std::list<Statement *> initialization = std::list<Statement *>() ); 137 138 IfStmt( const IfStmt &other ); … … 157 158 std::list<Statement *> statements; 158 159 159 SwitchStmt( Expression *condition, const std::list<Statement *> &statements );160 SwitchStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements ); 160 161 SwitchStmt( const SwitchStmt &other ); 161 162 virtual ~SwitchStmt(); … … 179 180 std::list<Statement *> stmts; 180 181 181 CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);182 CaseStmt( std::list<Label> labels, Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); 182 183 CaseStmt( const CaseStmt &other ); 183 184 virtual ~CaseStmt(); 184 185 185 static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() );186 static CaseStmt * makeDefault( std::list<Label> labels = std::list<Label>(), std::list<Statement *> stmts = std::list<Statement *>() ); 186 187 187 188 bool isDefault() const { return _isDefault; } … … 209 210 bool isDoWhile; 210 211 211 WhileStmt( Expression *condition,212 WhileStmt( std::list<Label> labels, Expression *condition, 212 213 Statement *body, bool isDoWhile = false ); 213 214 WhileStmt( const WhileStmt &other ); … … 234 235 Statement *body; 235 236 236 ForStmt( std::list< Statement *> initialization,237 ForStmt( std::list<Label> labels, std::list<Statement *> initialization, 237 238 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 238 239 ForStmt( const ForStmt &other ); … … 263 264 Type type; 264 265 265 BranchStmt( Label target, Type ) throw (SemanticError);266 BranchStmt( Expression *computedTarget, Type ) throw (SemanticError);266 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); 267 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError); 267 268 268 269 Label get_originalTarget() { return originalTarget; } … … 288 289 Expression *expr; 289 290 290 ReturnStmt( Expression *expr );291 ReturnStmt( std::list<Label> labels, Expression *expr ); 291 292 ReturnStmt( const ReturnStmt &other ); 292 293 virtual ~ReturnStmt(); … … 309 310 Expression * target; 310 311 311 ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr );312 ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr ); 312 313 ThrowStmt( const ThrowStmt &other ); 313 314 virtual ~ThrowStmt(); … … 331 332 FinallyStmt * finallyBlock; 332 333 333 TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );334 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 ); 334 335 TryStmt( const TryStmt &other ); 335 336 virtual ~TryStmt(); … … 357 358 Statement *body; 358 359 359 CatchStmt( Kind kind, Declaration *decl,360 CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, 360 361 Expression *cond, Statement *body ); 361 362 CatchStmt( const CatchStmt &other ); … … 380 381 CompoundStmt *block; 381 382 382 FinallyStmt( CompoundStmt *block );383 FinallyStmt( std::list<Label> labels, CompoundStmt *block ); 383 384 FinallyStmt( const FinallyStmt &other ); 384 385 virtual ~FinallyStmt(); … … 407 408 }; 408 409 409 WaitForStmt( );410 WaitForStmt( std::list<Label> labels = noLabels ); 410 411 WaitForStmt( const WaitForStmt & ); 411 412 virtual ~WaitForStmt(); … … 431 432 }; 432 433 433 class WithStmt : public Statement {434 public:435 std::list< Expression * > exprs;436 Statement * stmt;437 438 WithStmt( const std::list< Expression * > & exprs, Statement * stmt );439 WithStmt( const WithStmt & other );440 virtual ~WithStmt();441 442 virtual WithStmt * clone() const override { return new WithStmt( *this ); }443 virtual void accept( Visitor & v ) override { v.visit( this ); }444 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); }445 virtual void print( std::ostream & os, Indenter indent = {} ) const override;446 };447 448 434 449 435 // represents a declaration that occurs as part of a compound statement … … 452 438 Declaration *decl; 453 439 454 DeclStmt( Declaration *decl );440 DeclStmt( std::list<Label> labels, Declaration *decl ); 455 441 DeclStmt( const DeclStmt &other ); 456 442 virtual ~DeclStmt(); -
src/SynTree/SynTree.h
rc13e8dc8 r9c35431 55 55 class FinallyStmt; 56 56 class WaitForStmt; 57 class WithStmt;58 57 class NullStmt; 59 58 class DeclStmt; -
src/SynTree/TupleExpr.cc
rc13e8dc8 r9c35431 23 23 #include "Declaration.h" // for ObjectDecl 24 24 #include "Expression.h" // for Expression, TupleExpr, TupleIndexExpr 25 #include "SynTree/Label.h" // for Label 25 #include "SynTree/Label.h" // for Label, noLabels 26 26 #include "SynTree/Statement.h" // for CompoundStmt, DeclStmt, ExprStmt, Sta... 27 27 #include "Tuples/Tuples.h" // for makeTupleType … … 89 89 // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments 90 90 set_result( Tuples::makeTupleType( assigns ) ); 91 CompoundStmt * compoundStmt = new CompoundStmt( );91 CompoundStmt * compoundStmt = new CompoundStmt( noLabels ); 92 92 std::list< Statement * > & stmts = compoundStmt->get_kids(); 93 93 for ( ObjectDecl * obj : tempDecls ) { 94 stmts.push_back( new DeclStmt( obj ) );94 stmts.push_back( new DeclStmt( noLabels, obj ) ); 95 95 } 96 96 TupleExpr * tupleExpr = new TupleExpr( assigns ); 97 97 assert( tupleExpr->get_result() ); 98 stmts.push_back( new ExprStmt( tupleExpr ) );98 stmts.push_back( new ExprStmt( noLabels, tupleExpr ) ); 99 99 stmtExpr = new StmtExpr( compoundStmt ); 100 100 } -
src/SynTree/Type.h
rc13e8dc8 r9c35431 178 178 virtual bool isComplete() const { return true; } 179 179 180 virtual AggregateDecl * getAggr() { assertf( false, "Non-aggregate type: %s", toString( this ).c_str() ); }181 182 180 virtual Type *clone() const = 0; 183 181 virtual void accept( Visitor & v ) = 0; … … 407 405 virtual bool isComplete() const override; 408 406 409 virtual AggregateDecl * getAggr() override;410 411 407 /// Looks up the members of this struct named "name" and places them into "foundDecls". 412 408 /// Clones declarations into "foundDecls", caller responsible for freeing … … 440 436 441 437 virtual bool isComplete() const override; 442 443 virtual AggregateDecl * getAggr() override;444 438 445 439 /// looks up the members of this union named "name" and places them into "foundDecls" -
src/SynTree/Visitor.cc
rc13e8dc8 r9c35431 174 174 } 175 175 176 void Visitor::visit( WithStmt * withStmt ) { 177 acceptAll( withStmt->exprs, *this ); 178 maybeAccept( withStmt->stmt, *this ); 179 } 180 181 void Visitor::visit( NullStmt * ) { 176 void Visitor::visit( __attribute__((unused)) NullStmt *nullStmt ) { 182 177 } 183 178 -
src/SynTree/Visitor.h
rc13e8dc8 r9c35431 52 52 virtual void visit( FinallyStmt * finallyStmt ); 53 53 virtual void visit( WaitForStmt * waitforStmt ); 54 virtual void visit( WithStmt * withStmt );55 54 virtual void visit( NullStmt * nullStmt ); 56 55 virtual void visit( DeclStmt * declStmt ); -
src/Tuples/TupleAssignment.cc
rc13e8dc8 r9c35431 23 23 24 24 #include "CodeGen/OperatorTable.h" 25 #include "Common/PassVisitor.h"26 25 #include "Common/UniqueName.h" // for UniqueName 27 26 #include "Common/utility.h" // for zipWith … … 62 61 struct Matcher { 63 62 public: 64 Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, const 63 Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, const 65 64 ResolvExpr::AltList& rhs ); 66 65 virtual ~Matcher() {} … … 76 75 struct MassAssignMatcher : public Matcher { 77 76 public: 78 MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 77 MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 79 78 const ResolvExpr::AltList& rhs ) : Matcher(spotter, lhs, rhs) {} 80 79 virtual void match( std::list< Expression * > &out ); … … 83 82 struct MultipleAssignMatcher : public Matcher { 84 83 public: 85 MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 84 MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 86 85 const ResolvExpr::AltList& rhs ) : Matcher(spotter, lhs, rhs) {} 87 86 virtual void match( std::list< Expression * > &out ); … … 120 119 } 121 120 122 void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * expr, 121 void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * expr, 123 122 std::vector<ResolvExpr::AlternativeFinder> &args ) { 124 123 TupleAssignSpotter spotter( currentFinder ); … … 129 128 : currentFinder(f) {} 130 129 131 void TupleAssignSpotter::spot( UntypedExpr * expr, 130 void TupleAssignSpotter::spot( UntypedExpr * expr, 132 131 std::vector<ResolvExpr::AlternativeFinder> &args ) { 133 132 if ( NameExpr *op = dynamic_cast< NameExpr * >(expr->get_function()) ) { … … 138 137 if ( args.size() == 0 ) return; 139 138 140 // if an assignment only takes 1 argument, that's odd, but maybe someone wrote 139 // if an assignment only takes 1 argument, that's odd, but maybe someone wrote 141 140 // the function, in which case AlternativeFinder will handle it normally 142 141 if ( args.size() == 1 && CodeGen::isAssignment( fname ) ) return; … … 147 146 if ( ! refToTuple(lhsAlt.expr) ) continue; 148 147 149 // explode is aware of casts - ensure every LHS expression is sent into explode 148 // explode is aware of casts - ensure every LHS expression is sent into explode 150 149 // with a reference cast 151 // xxx - this seems to change the alternatives before the normal 150 // xxx - this seems to change the alternatives before the normal 152 151 // AlternativeFinder flow; maybe this is desired? 153 152 if ( ! dynamic_cast<CastExpr*>( lhsAlt.expr ) ) { 154 lhsAlt.expr = new CastExpr( lhsAlt.expr, 155 new ReferenceType( Type::Qualifiers(), 153 lhsAlt.expr = new CastExpr( lhsAlt.expr, 154 new ReferenceType( Type::Qualifiers(), 156 155 lhsAlt.expr->get_result()->clone() ) ); 157 156 } … … 161 160 explode( lhsAlt, currentFinder.get_indexer(), back_inserter(lhs), true ); 162 161 for ( ResolvExpr::Alternative& alt : lhs ) { 163 // each LHS value must be a reference - some come in with a cast expression, 162 // each LHS value must be a reference - some come in with a cast expression, 164 163 // if not just cast to reference here 165 164 if ( ! dynamic_cast<ReferenceType*>( alt.expr->get_result() ) ) { 166 alt.expr = new CastExpr( alt.expr, 167 new ReferenceType( Type::Qualifiers(), 165 alt.expr = new CastExpr( alt.expr, 166 new ReferenceType( Type::Qualifiers(), 168 167 alt.expr->get_result()->clone() ) ); 169 168 } … … 179 178 // TODO build iterative version of this instead of using combos 180 179 std::vector< ResolvExpr::AltList > rhsAlts; 181 combos( std::next(args.begin(), 1), args.end(), 180 combos( std::next(args.begin(), 1), args.end(), 182 181 std::back_inserter( rhsAlts ) ); 183 182 for ( const ResolvExpr::AltList& rhsAlt : rhsAlts ) { 184 183 // multiple assignment 185 184 ResolvExpr::AltList rhs; 186 explode( rhsAlt, currentFinder.get_indexer(), 185 explode( rhsAlt, currentFinder.get_indexer(), 187 186 std::back_inserter(rhs), true ); 188 187 matcher.reset( new MultipleAssignMatcher( *this, lhs, rhs ) ); … … 194 193 if ( isTuple(rhsAlt.expr) ) { 195 194 // multiple assignment 196 explode( rhsAlt, currentFinder.get_indexer(), 195 explode( rhsAlt, currentFinder.get_indexer(), 197 196 std::back_inserter(rhs), true ); 198 197 matcher.reset( new MultipleAssignMatcher( *this, lhs, rhs ) ); … … 223 222 ResolvExpr::AltList current; 224 223 // now resolve new assignments 225 for ( std::list< Expression * >::iterator i = new_assigns.begin(); 224 for ( std::list< Expression * >::iterator i = new_assigns.begin(); 226 225 i != new_assigns.end(); ++i ) { 227 226 PRINT( … … 230 229 ) 231 230 232 ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(), 231 ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(), 233 232 currentFinder.get_environ() }; 234 233 try { … … 254 253 // xxx -- was push_front 255 254 currentFinder.get_alternatives().push_back( ResolvExpr::Alternative( 256 new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, 255 new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, 257 256 ResolvExpr::sumCost( current ) + matcher->baseCost ) ); 258 257 } 259 258 260 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, 261 const ResolvExpr::AltList &lhs, const ResolvExpr::AltList &rhs ) 262 : lhs(lhs), rhs(rhs), spotter(spotter), 259 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, 260 const ResolvExpr::AltList &lhs, const ResolvExpr::AltList &rhs ) 261 : lhs(lhs), rhs(rhs), spotter(spotter), 263 262 baseCost( ResolvExpr::sumCost( lhs ) + ResolvExpr::sumCost( rhs ) ) { 264 263 simpleCombineEnvironments( lhs.begin(), lhs.end(), compositeEnv ); … … 278 277 // xxx - maybe this should happen in alternative finder for every StmtExpr? 279 278 // xxx - it's possible that these environments could contain some useful information. Maybe the right thing to do is aggregate the environments and pass the aggregate back to be added into the compositeEnv 280 struct EnvRemover { 281 void previsit( ExprStmt * stmt ) { 282 delete stmt->expr->env; 283 stmt->expr->env = nullptr; 279 struct EnvRemover : public Visitor { 280 virtual void visit( ExprStmt * stmt ) { 281 delete stmt->get_expr()->get_env(); 282 stmt->get_expr()->set_env( nullptr ); 283 Visitor::visit( stmt ); 284 284 } 285 285 }; … … 293 293 ret->set_init( ctorInit ); 294 294 ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object 295 PassVisitor<EnvRemover>rm; // remove environments from subexpressions of StmtExprs295 EnvRemover rm; // remove environments from subexpressions of StmtExprs 296 296 ctorInit->accept( rm ); 297 297 } -
src/Tuples/TupleExpansion.cc
rc13e8dc8 r9c35431 315 315 namespace { 316 316 /// determines if impurity (read: side-effects) may exist in a piece of code. Currently gives a very crude approximation, wherein any function call expression means the code may be impure 317 struct ImpurityDetector : public WithShortCircuiting { 317 class ImpurityDetector : public Visitor { 318 public: 318 319 ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {} 319 320 320 void previsit( ApplicationExpr * appExpr ) {321 visit_children = false;321 typedef Visitor Parent; 322 virtual void visit( ApplicationExpr * appExpr ) { 322 323 if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) { 323 324 if ( function->get_linkage() == LinkageSpec::Intrinsic ) { 324 325 if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) { 325 326 // intrinsic dereference, subscript are pure, but need to recursively look for impurity 326 visit_children = true;327 Parent::visit( appExpr ); 327 328 return; 328 329 } … … 331 332 maybeImpure = true; 332 333 } 333 v oid previsit( UntypedExpr * ) { maybeImpure = true; visit_children = false; }334 v oid previsit( UniqueExpr *) {334 virtual void visit( UntypedExpr * ) { maybeImpure = true; } 335 virtual void visit( UniqueExpr * unq ) { 335 336 if ( ignoreUnique ) { 336 337 // bottom out at unique expression. 337 338 // The existence of a unique expression doesn't change the purity of an expression. 338 339 // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression. 339 visit_children = false;340 340 return; 341 341 } 342 maybeAccept( unq->expr, *this ); 342 343 } 343 344 … … 348 349 349 350 bool maybeImpure( Expression * expr ) { 350 PassVisitor<ImpurityDetector>detector( false );351 ImpurityDetector detector( false ); 351 352 expr->accept( detector ); 352 return detector. pass.maybeImpure;353 return detector.maybeImpure; 353 354 } 354 355 355 356 bool maybeImpureIgnoreUnique( Expression * expr ) { 356 PassVisitor<ImpurityDetector>detector( true );357 ImpurityDetector detector( true ); 357 358 expr->accept( detector ); 358 return detector. pass.maybeImpure;359 return detector.maybeImpure; 359 360 } 360 361 } // namespace Tuples -
src/driver/cfa.cc
rc13e8dc8 r9c35431 275 275 args[nargs] = "-Xlinker"; 276 276 nargs += 1; 277 args[nargs] = "--undefined=__ cfaabi_dbg_bits_write";277 args[nargs] = "--undefined=__lib_debug_write"; 278 278 nargs += 1; 279 279 -
src/libcfa/Makefile.am
rc13e8dc8 r9c35431 55 55 56 56 libobjs = ${headers:=.o} 57 libsrc = libcfa-prelude.c interpose.c bits/debug.c ${headers:=.c} \57 libsrc = libcfa-prelude.c interpose.c libhdr/libdebug.c ${headers:=.c} \ 58 58 assert.c exception.c virtual.c 59 59 … … 100 100 math \ 101 101 gmp \ 102 bits/align.h \103 102 bits/containers.h \ 104 103 bits/defs.h \ 105 bits/debug.h \106 104 bits/locks.h \ 107 concurrency/invoke.h 105 concurrency/invoke.h \ 106 libhdr.h \ 107 libhdr/libalign.h \ 108 libhdr/libdebug.h \ 109 libhdr/libtools.h 108 110 109 111 CLEANFILES = libcfa-prelude.c -
src/libcfa/Makefile.in
rc13e8dc8 r9c35431 149 149 libcfa_d_a_LIBADD = 150 150 am__libcfa_d_a_SOURCES_DIST = libcfa-prelude.c interpose.c \ 151 bits/debug.c fstream.c iostream.c iterator.c limits.c \151 libhdr/libdebug.c fstream.c iostream.c iterator.c limits.c \ 152 152 rational.c stdlib.c containers/maybe.c containers/pair.c \ 153 153 containers/result.c containers/vector.c \ … … 175 175 @BUILD_CONCURRENCY_TRUE@ concurrency/libcfa_d_a-preemption.$(OBJEXT) 176 176 am__objects_4 = libcfa_d_a-libcfa-prelude.$(OBJEXT) \ 177 libcfa_d_a-interpose.$(OBJEXT) bits/libcfa_d_a-debug.$(OBJEXT)\178 $(am__objects_2) libcfa_d_a-assert.$(OBJEXT) \179 libcfa_d_a- exception.$(OBJEXT) libcfa_d_a-virtual.$(OBJEXT) \180 $(am__objects_3)177 libcfa_d_a-interpose.$(OBJEXT) \ 178 libhdr/libcfa_d_a-libdebug.$(OBJEXT) $(am__objects_2) \ 179 libcfa_d_a-assert.$(OBJEXT) libcfa_d_a-exception.$(OBJEXT) \ 180 libcfa_d_a-virtual.$(OBJEXT) $(am__objects_3) 181 181 am_libcfa_d_a_OBJECTS = $(am__objects_4) 182 182 libcfa_d_a_OBJECTS = $(am_libcfa_d_a_OBJECTS) 183 183 libcfa_a_AR = $(AR) $(ARFLAGS) 184 184 libcfa_a_LIBADD = 185 am__libcfa_a_SOURCES_DIST = libcfa-prelude.c interpose.c bits/debug.c \ 186 fstream.c iostream.c iterator.c limits.c rational.c stdlib.c \ 187 containers/maybe.c containers/pair.c containers/result.c \ 188 containers/vector.c concurrency/coroutine.c \ 189 concurrency/thread.c concurrency/kernel.c \ 190 concurrency/monitor.c assert.c exception.c virtual.c \ 191 concurrency/CtxSwitch-@MACHINE_TYPE@.S concurrency/alarm.c \ 192 concurrency/invoke.c concurrency/preemption.c 185 am__libcfa_a_SOURCES_DIST = libcfa-prelude.c interpose.c \ 186 libhdr/libdebug.c fstream.c iostream.c iterator.c limits.c \ 187 rational.c stdlib.c containers/maybe.c containers/pair.c \ 188 containers/result.c containers/vector.c \ 189 concurrency/coroutine.c concurrency/thread.c \ 190 concurrency/kernel.c concurrency/monitor.c assert.c \ 191 exception.c virtual.c concurrency/CtxSwitch-@MACHINE_TYPE@.S \ 192 concurrency/alarm.c concurrency/invoke.c \ 193 concurrency/preemption.c 193 194 @BUILD_CONCURRENCY_TRUE@am__objects_5 = concurrency/libcfa_a-coroutine.$(OBJEXT) \ 194 195 @BUILD_CONCURRENCY_TRUE@ concurrency/libcfa_a-thread.$(OBJEXT) \ … … 207 208 @BUILD_CONCURRENCY_TRUE@ concurrency/libcfa_a-preemption.$(OBJEXT) 208 209 am__objects_8 = libcfa_a-libcfa-prelude.$(OBJEXT) \ 209 libcfa_a-interpose.$(OBJEXT) bits/libcfa_a-debug.$(OBJEXT)\210 $(am__objects_6) libcfa_a-assert.$(OBJEXT) \211 libcfa_a- exception.$(OBJEXT) libcfa_a-virtual.$(OBJEXT) \212 $(am__objects_7)210 libcfa_a-interpose.$(OBJEXT) \ 211 libhdr/libcfa_a-libdebug.$(OBJEXT) $(am__objects_6) \ 212 libcfa_a-assert.$(OBJEXT) libcfa_a-exception.$(OBJEXT) \ 213 libcfa_a-virtual.$(OBJEXT) $(am__objects_7) 213 214 am_libcfa_a_OBJECTS = $(am__objects_8) 214 215 libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS) … … 263 264 containers/result containers/vector concurrency/coroutine \ 264 265 concurrency/thread concurrency/kernel concurrency/monitor \ 265 ${shell echo stdhdr/*} math gmp bits/align.h bits/containers.h \ 266 bits/defs.h bits/debug.h bits/locks.h concurrency/invoke.h 266 ${shell echo stdhdr/*} math gmp bits/containers.h bits/defs.h \ 267 bits/locks.h concurrency/invoke.h libhdr.h libhdr/libalign.h \ 268 libhdr/libdebug.h libhdr/libtools.h 267 269 HEADERS = $(nobase_cfa_include_HEADERS) 268 270 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) … … 422 424 containers/vector $(am__append_3) 423 425 libobjs = ${headers:=.o} 424 libsrc = libcfa-prelude.c interpose.c bits/debug.c ${headers:=.c} \426 libsrc = libcfa-prelude.c interpose.c libhdr/libdebug.c ${headers:=.c} \ 425 427 assert.c exception.c virtual.c $(am__append_4) 426 428 libcfa_a_SOURCES = ${libsrc} … … 435 437 math \ 436 438 gmp \ 437 bits/align.h \438 439 bits/containers.h \ 439 440 bits/defs.h \ 440 bits/debug.h \441 441 bits/locks.h \ 442 concurrency/invoke.h 442 concurrency/invoke.h \ 443 libhdr.h \ 444 libhdr/libalign.h \ 445 libhdr/libdebug.h \ 446 libhdr/libtools.h 443 447 444 448 CLEANFILES = libcfa-prelude.c … … 507 511 clean-libLIBRARIES: 508 512 -test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES) 509 bits/$(am__dirstamp):510 @$(MKDIR_P) bits511 @: > bits/$(am__dirstamp)512 bits/$(DEPDIR)/$(am__dirstamp):513 @$(MKDIR_P) bits/$(DEPDIR)514 @: > bits/$(DEPDIR)/$(am__dirstamp)515 bits/libcfa_d_a-debug.$(OBJEXT): bits/$(am__dirstamp) \516 bits/$(DEPDIR)/$(am__dirstamp)513 libhdr/$(am__dirstamp): 514 @$(MKDIR_P) libhdr 515 @: > libhdr/$(am__dirstamp) 516 libhdr/$(DEPDIR)/$(am__dirstamp): 517 @$(MKDIR_P) libhdr/$(DEPDIR) 518 @: > libhdr/$(DEPDIR)/$(am__dirstamp) 519 libhdr/libcfa_d_a-libdebug.$(OBJEXT): libhdr/$(am__dirstamp) \ 520 libhdr/$(DEPDIR)/$(am__dirstamp) 517 521 containers/$(am__dirstamp): 518 522 @$(MKDIR_P) containers … … 559 563 $(AM_V_AR)$(libcfa_d_a_AR) libcfa-d.a $(libcfa_d_a_OBJECTS) $(libcfa_d_a_LIBADD) 560 564 $(AM_V_at)$(RANLIB) libcfa-d.a 561 bits/libcfa_a-debug.$(OBJEXT): bits/$(am__dirstamp) \562 bits/$(DEPDIR)/$(am__dirstamp)565 libhdr/libcfa_a-libdebug.$(OBJEXT): libhdr/$(am__dirstamp) \ 566 libhdr/$(DEPDIR)/$(am__dirstamp) 563 567 containers/libcfa_a-maybe.$(OBJEXT): containers/$(am__dirstamp) \ 564 568 containers/$(DEPDIR)/$(am__dirstamp) … … 592 596 mostlyclean-compile: 593 597 -rm -f *.$(OBJEXT) 594 -rm -f bits/*.$(OBJEXT)595 598 -rm -f concurrency/*.$(OBJEXT) 596 599 -rm -f containers/*.$(OBJEXT) 600 -rm -f libhdr/*.$(OBJEXT) 597 601 598 602 distclean-compile: … … 621 625 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-stdlib.Po@am__quote@ 622 626 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-virtual.Po@am__quote@ 623 @AMDEP_TRUE@@am__include@ @am__quote@bits/$(DEPDIR)/libcfa_a-debug.Po@am__quote@624 @AMDEP_TRUE@@am__include@ @am__quote@bits/$(DEPDIR)/libcfa_d_a-debug.Po@am__quote@625 627 @AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/CtxSwitch-@MACHINE_TYPE@.Po@am__quote@ 626 628 @AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_a-alarm.Po@am__quote@ … … 646 648 @AMDEP_TRUE@@am__include@ @am__quote@containers/$(DEPDIR)/libcfa_d_a-result.Po@am__quote@ 647 649 @AMDEP_TRUE@@am__include@ @am__quote@containers/$(DEPDIR)/libcfa_d_a-vector.Po@am__quote@ 650 @AMDEP_TRUE@@am__include@ @am__quote@libhdr/$(DEPDIR)/libcfa_a-libdebug.Po@am__quote@ 651 @AMDEP_TRUE@@am__include@ @am__quote@libhdr/$(DEPDIR)/libcfa_d_a-libdebug.Po@am__quote@ 648 652 649 653 .S.o: … … 700 704 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o libcfa_d_a-interpose.obj `if test -f 'interpose.c'; then $(CYGPATH_W) 'interpose.c'; else $(CYGPATH_W) '$(srcdir)/interpose.c'; fi` 701 705 702 bits/libcfa_d_a-debug.o: bits/debug.c703 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT bits/libcfa_d_a-debug.o -MD -MP -MF bits/$(DEPDIR)/libcfa_d_a-debug.Tpo -c -o bits/libcfa_d_a-debug.o `test -f 'bits/debug.c' || echo '$(srcdir)/'`bits/debug.c704 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) bits/$(DEPDIR)/libcfa_d_a-debug.Tpo bits/$(DEPDIR)/libcfa_d_a-debug.Po705 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source=' bits/debug.c' object='bits/libcfa_d_a-debug.o' libtool=no @AMDEPBACKSLASH@706 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 707 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o bits/libcfa_d_a-debug.o `test -f 'bits/debug.c' || echo '$(srcdir)/'`bits/debug.c708 709 bits/libcfa_d_a-debug.obj: bits/debug.c710 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT bits/libcfa_d_a-debug.obj -MD -MP -MF bits/$(DEPDIR)/libcfa_d_a-debug.Tpo -c -o bits/libcfa_d_a-debug.obj `if test -f 'bits/debug.c'; then $(CYGPATH_W) 'bits/debug.c'; else $(CYGPATH_W) '$(srcdir)/bits/debug.c'; fi`711 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) bits/$(DEPDIR)/libcfa_d_a-debug.Tpo bits/$(DEPDIR)/libcfa_d_a-debug.Po712 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source=' bits/debug.c' object='bits/libcfa_d_a-debug.obj' libtool=no @AMDEPBACKSLASH@713 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 714 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o bits/libcfa_d_a-debug.obj `if test -f 'bits/debug.c'; then $(CYGPATH_W) 'bits/debug.c'; else $(CYGPATH_W) '$(srcdir)/bits/debug.c'; fi`706 libhdr/libcfa_d_a-libdebug.o: libhdr/libdebug.c 707 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT libhdr/libcfa_d_a-libdebug.o -MD -MP -MF libhdr/$(DEPDIR)/libcfa_d_a-libdebug.Tpo -c -o libhdr/libcfa_d_a-libdebug.o `test -f 'libhdr/libdebug.c' || echo '$(srcdir)/'`libhdr/libdebug.c 708 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libhdr/$(DEPDIR)/libcfa_d_a-libdebug.Tpo libhdr/$(DEPDIR)/libcfa_d_a-libdebug.Po 709 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libhdr/libdebug.c' object='libhdr/libcfa_d_a-libdebug.o' libtool=no @AMDEPBACKSLASH@ 710 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 711 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o libhdr/libcfa_d_a-libdebug.o `test -f 'libhdr/libdebug.c' || echo '$(srcdir)/'`libhdr/libdebug.c 712 713 libhdr/libcfa_d_a-libdebug.obj: libhdr/libdebug.c 714 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT libhdr/libcfa_d_a-libdebug.obj -MD -MP -MF libhdr/$(DEPDIR)/libcfa_d_a-libdebug.Tpo -c -o libhdr/libcfa_d_a-libdebug.obj `if test -f 'libhdr/libdebug.c'; then $(CYGPATH_W) 'libhdr/libdebug.c'; else $(CYGPATH_W) '$(srcdir)/libhdr/libdebug.c'; fi` 715 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libhdr/$(DEPDIR)/libcfa_d_a-libdebug.Tpo libhdr/$(DEPDIR)/libcfa_d_a-libdebug.Po 716 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libhdr/libdebug.c' object='libhdr/libcfa_d_a-libdebug.obj' libtool=no @AMDEPBACKSLASH@ 717 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 718 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o libhdr/libcfa_d_a-libdebug.obj `if test -f 'libhdr/libdebug.c'; then $(CYGPATH_W) 'libhdr/libdebug.c'; else $(CYGPATH_W) '$(srcdir)/libhdr/libdebug.c'; fi` 715 719 716 720 libcfa_d_a-fstream.o: fstream.c … … 994 998 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o libcfa_a-interpose.obj `if test -f 'interpose.c'; then $(CYGPATH_W) 'interpose.c'; else $(CYGPATH_W) '$(srcdir)/interpose.c'; fi` 995 999 996 bits/libcfa_a-debug.o: bits/debug.c997 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT bits/libcfa_a-debug.o -MD -MP -MF bits/$(DEPDIR)/libcfa_a-debug.Tpo -c -o bits/libcfa_a-debug.o `test -f 'bits/debug.c' || echo '$(srcdir)/'`bits/debug.c998 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) bits/$(DEPDIR)/libcfa_a-debug.Tpo bits/$(DEPDIR)/libcfa_a-debug.Po999 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source=' bits/debug.c' object='bits/libcfa_a-debug.o' libtool=no @AMDEPBACKSLASH@1000 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1001 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o bits/libcfa_a-debug.o `test -f 'bits/debug.c' || echo '$(srcdir)/'`bits/debug.c1002 1003 bits/libcfa_a-debug.obj: bits/debug.c1004 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT bits/libcfa_a-debug.obj -MD -MP -MF bits/$(DEPDIR)/libcfa_a-debug.Tpo -c -o bits/libcfa_a-debug.obj `if test -f 'bits/debug.c'; then $(CYGPATH_W) 'bits/debug.c'; else $(CYGPATH_W) '$(srcdir)/bits/debug.c'; fi`1005 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) bits/$(DEPDIR)/libcfa_a-debug.Tpo bits/$(DEPDIR)/libcfa_a-debug.Po1006 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source=' bits/debug.c' object='bits/libcfa_a-debug.obj' libtool=no @AMDEPBACKSLASH@1007 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1008 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o bits/libcfa_a-debug.obj `if test -f 'bits/debug.c'; then $(CYGPATH_W) 'bits/debug.c'; else $(CYGPATH_W) '$(srcdir)/bits/debug.c'; fi`1000 libhdr/libcfa_a-libdebug.o: libhdr/libdebug.c 1001 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT libhdr/libcfa_a-libdebug.o -MD -MP -MF libhdr/$(DEPDIR)/libcfa_a-libdebug.Tpo -c -o libhdr/libcfa_a-libdebug.o `test -f 'libhdr/libdebug.c' || echo '$(srcdir)/'`libhdr/libdebug.c 1002 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libhdr/$(DEPDIR)/libcfa_a-libdebug.Tpo libhdr/$(DEPDIR)/libcfa_a-libdebug.Po 1003 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libhdr/libdebug.c' object='libhdr/libcfa_a-libdebug.o' libtool=no @AMDEPBACKSLASH@ 1004 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1005 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o libhdr/libcfa_a-libdebug.o `test -f 'libhdr/libdebug.c' || echo '$(srcdir)/'`libhdr/libdebug.c 1006 1007 libhdr/libcfa_a-libdebug.obj: libhdr/libdebug.c 1008 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT libhdr/libcfa_a-libdebug.obj -MD -MP -MF libhdr/$(DEPDIR)/libcfa_a-libdebug.Tpo -c -o libhdr/libcfa_a-libdebug.obj `if test -f 'libhdr/libdebug.c'; then $(CYGPATH_W) 'libhdr/libdebug.c'; else $(CYGPATH_W) '$(srcdir)/libhdr/libdebug.c'; fi` 1009 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libhdr/$(DEPDIR)/libcfa_a-libdebug.Tpo libhdr/$(DEPDIR)/libcfa_a-libdebug.Po 1010 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libhdr/libdebug.c' object='libhdr/libcfa_a-libdebug.obj' libtool=no @AMDEPBACKSLASH@ 1011 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1012 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o libhdr/libcfa_a-libdebug.obj `if test -f 'libhdr/libdebug.c'; then $(CYGPATH_W) 'libhdr/libdebug.c'; else $(CYGPATH_W) '$(srcdir)/libhdr/libdebug.c'; fi` 1009 1013 1010 1014 libcfa_a-fstream.o: fstream.c … … 1407 1411 -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) 1408 1412 -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) 1409 -rm -f bits/$(DEPDIR)/$(am__dirstamp)1410 -rm -f bits/$(am__dirstamp)1411 1413 -rm -f concurrency/$(DEPDIR)/$(am__dirstamp) 1412 1414 -rm -f concurrency/$(am__dirstamp) 1413 1415 -rm -f containers/$(DEPDIR)/$(am__dirstamp) 1414 1416 -rm -f containers/$(am__dirstamp) 1417 -rm -f libhdr/$(DEPDIR)/$(am__dirstamp) 1418 -rm -f libhdr/$(am__dirstamp) 1415 1419 1416 1420 maintainer-clean-generic: … … 1422 1426 1423 1427 distclean: distclean-am 1424 -rm -rf ./$(DEPDIR) bits/$(DEPDIR) concurrency/$(DEPDIR) containers/$(DEPDIR)1428 -rm -rf ./$(DEPDIR) concurrency/$(DEPDIR) containers/$(DEPDIR) libhdr/$(DEPDIR) 1425 1429 -rm -f Makefile 1426 1430 distclean-am: clean-am distclean-compile distclean-generic \ … … 1468 1472 1469 1473 maintainer-clean: maintainer-clean-am 1470 -rm -rf ./$(DEPDIR) bits/$(DEPDIR) concurrency/$(DEPDIR) containers/$(DEPDIR)1474 -rm -rf ./$(DEPDIR) concurrency/$(DEPDIR) containers/$(DEPDIR) libhdr/$(DEPDIR) 1471 1475 -rm -f Makefile 1472 1476 maintainer-clean-am: distclean-am maintainer-clean-generic \ -
src/libcfa/assert.c
rc13e8dc8 r9c35431 17 17 #include <stdarg.h> // varargs 18 18 #include <stdio.h> // fprintf 19 #include " bits/debug.h"19 #include "libhdr/libdebug.h" 20 20 21 21 extern "C" { … … 26 26 // called by macro assert in assert.h 27 27 void __assert_fail( const char *assertion, const char *file, unsigned int line, const char *function ) { 28 __ cfaabi_dbg_bits_print_safe( CFA_ASSERT_FMT ".\n", __progname, function, line, file );28 __lib_debug_print_safe( CFA_ASSERT_FMT ".\n", __progname, function, line, file ); 29 29 abort(); 30 30 } … … 32 32 // called by macro assertf 33 33 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) { 34 __ cfaabi_dbg_bits_acquire();35 __ cfaabi_dbg_bits_print_nolock( CFA_ASSERT_FMT ": ", __progname, function, line, file );34 __lib_debug_acquire(); 35 __lib_debug_print_nolock( CFA_ASSERT_FMT ": ", __progname, function, line, file ); 36 36 37 37 va_list args; 38 38 va_start( args, fmt ); 39 __ cfaabi_dbg_bits_print_vararg( fmt, args );39 __lib_debug_print_vararg( fmt, args ); 40 40 va_end( args ); 41 41 42 __ cfaabi_dbg_bits_print_nolock( "\n" );43 __ cfaabi_dbg_bits_release();42 __lib_debug_print_nolock( "\n" ); 43 __lib_debug_release(); 44 44 abort(); 45 45 } -
src/libcfa/bits/containers.h
rc13e8dc8 r9c35431 15 15 #pragma once 16 16 17 #include "bits/align.h"18 17 #include "bits/defs.h" 18 #include "libhdr.h" 19 19 20 20 //----------------------------------------------------------------------------- -
src/libcfa/bits/defs.h
rc13e8dc8 r9c35431 32 32 #define __cfa_anonymous_object __cfa_anonymous_object 33 33 #endif 34 35 #ifdef __cforall36 extern "C" {37 #endif38 void abortf( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__));39 #ifdef __cforall40 }41 #endif -
src/libcfa/bits/locks.h
rc13e8dc8 r9c35431 16 16 #pragma once 17 17 18 #include "bits/debug.h"19 18 #include "bits/defs.h" 19 20 #include "libhdr.h" 20 21 21 22 // pause to prevent excess processor bus usage … … 64 65 65 66 // Lock the spinlock, return false if already acquired 66 static inline _Bool try_lock ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {67 static inline _Bool try_lock ( __spinlock_t & this DEBUG_CTX_PARAM2 ) { 67 68 _Bool result = __lock_test_and_test_and_set( this.lock ); 68 __cfaabi_dbg_debug_do(69 LIB_DEBUG_DO( 69 70 if( result ) { 70 71 this.prev_name = caller; … … 76 77 77 78 // Lock the spinlock, spin if already acquired 78 static inline void lock( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {79 static inline void lock( __spinlock_t & this DEBUG_CTX_PARAM2 ) { 79 80 #ifndef NOEXPBACK 80 81 enum { SPIN_START = 4, SPIN_END = 64 * 1024, }; … … 97 98 #endif 98 99 } 99 __cfaabi_dbg_debug_do(100 LIB_DEBUG_DO( 100 101 this.prev_name = caller; 101 102 this.prev_thrd = this_thread; … … 104 105 105 106 // Lock the spinlock, spin if already acquired 106 static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {107 static inline void lock_yield( __spinlock_t & this DEBUG_CTX_PARAM2 ) { 107 108 for ( unsigned int i = 1;; i += 1 ) { 108 109 if ( __lock_test_and_test_and_set( this.lock ) ) break; 109 110 yield( i ); 110 111 } 111 __cfaabi_dbg_debug_do(112 LIB_DEBUG_DO( 112 113 this.prev_name = caller; 113 114 this.prev_thrd = this_thread; -
src/libcfa/concurrency/alarm.c
rc13e8dc8 r9c35431 23 23 } 24 24 25 #include "libhdr.h" 26 25 27 #include "alarm.h" 26 28 #include "kernel_private.h" … … 108 110 } 109 111 110 __cfaabi_dbg_debug_do( bool validate( alarm_list_t * this ) {112 LIB_DEBUG_DO( bool validate( alarm_list_t * this ) { 111 113 alarm_node_t ** it = &this->head; 112 114 while( (*it) ) { … … 184 186 185 187 disable_interrupts(); 186 lock( event_kernel->lock __cfaabi_dbg_ctx2 );188 lock( event_kernel->lock DEBUG_CTX2 ); 187 189 { 188 190 verify( validate( alarms ) ); … … 196 198 unlock( event_kernel->lock ); 197 199 this->set = true; 198 enable_interrupts( __cfaabi_dbg_ctx);200 enable_interrupts( DEBUG_CTX ); 199 201 } 200 202 201 203 void unregister_self( alarm_node_t * this ) { 202 204 disable_interrupts(); 203 lock( event_kernel->lock __cfaabi_dbg_ctx2 );205 lock( event_kernel->lock DEBUG_CTX2 ); 204 206 { 205 207 verify( validate( &event_kernel->alarms ) ); … … 207 209 } 208 210 unlock( event_kernel->lock ); 209 enable_interrupts( __cfaabi_dbg_ctx);211 enable_interrupts( DEBUG_CTX ); 210 212 this->set = false; 211 213 } -
src/libcfa/concurrency/coroutine.c
rc13e8dc8 r9c35431 29 29 #define __CFA_INVOKE_PRIVATE__ 30 30 #include "invoke.h" 31 31 32 32 33 //----------------------------------------------------------------------------- … … 75 76 void ^?{}(coStack_t & this) { 76 77 if ( ! this.userStack && this.storage ) { 77 __cfaabi_dbg_debug_do(78 LIB_DEBUG_DO( 78 79 if ( mprotect( this.storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) { 79 80 abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) ); … … 130 131 131 132 // assume malloc has 8 byte alignment so add 8 to allow rounding up to 16 byte alignment 132 __cfaabi_dbg_debug_do( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) );133 __cfaabi_dbg_no_debug_do( this->storage = malloc( cxtSize + this->size + 8 ) );133 LIB_DEBUG_DO( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) ); 134 LIB_NO_DEBUG_DO( this->storage = malloc( cxtSize + this->size + 8 ) ); 134 135 135 __cfaabi_dbg_debug_do(136 LIB_DEBUG_DO( 136 137 if ( mprotect( this->storage, pageSize, PROT_NONE ) == -1 ) { 137 138 abortf( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) ); … … 143 144 } // if 144 145 145 __cfaabi_dbg_debug_do( this->limit = (char *)this->storage + pageSize );146 __cfaabi_dbg_no_debug_do( this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ) ); // minimum alignment146 LIB_DEBUG_DO( this->limit = (char *)this->storage + pageSize ); 147 LIB_NO_DEBUG_DO( this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ) ); // minimum alignment 147 148 148 149 } else { -
src/libcfa/concurrency/invoke.c
rc13e8dc8 r9c35431 18 18 #include <stdio.h> 19 19 20 #include "libhdr.h" 20 21 #include "invoke.h" 21 22 … … 30 31 extern void __leave_thread_monitor( struct thread_desc * this ); 31 32 extern void disable_interrupts(); 32 extern void enable_interrupts( __cfaabi_dbg_ctx_param);33 extern void enable_interrupts( DEBUG_CTX_PARAM ); 33 34 34 35 void CtxInvokeCoroutine( 35 void (*main)(void *),36 struct coroutine_desc *(*get_coroutine)(void *),37 void *this36 void (*main)(void *), 37 struct coroutine_desc *(*get_coroutine)(void *), 38 void *this 38 39 ) { 39 struct coroutine_desc* cor = get_coroutine( this);40 // LIB_DEBUG_PRINTF("Invoke Coroutine : Received %p (main %p, get_c %p)\n", this, main, get_coroutine); 40 41 41 if(cor->state == Primed) { 42 __suspend_internal(); 43 } 42 struct coroutine_desc* cor = get_coroutine( this ); 44 43 45 cor->state = Active; 44 if(cor->state == Primed) { 45 __suspend_internal(); 46 } 46 47 47 main( this );48 cor->state = Active; 48 49 49 cor->state = Halted;50 main( this ); 50 51 51 //Final suspend, should never return 52 __leave_coroutine(); 53 abortf("Resumed dead coroutine"); 52 cor->state = Halted; 53 54 //Final suspend, should never return 55 __leave_coroutine(); 56 abortf("Resumed dead coroutine"); 54 57 } 55 58 56 59 void CtxInvokeThread( 57 void (*dtor)(void *),58 void (*main)(void *),59 struct thread_desc *(*get_thread)(void *),60 void *this60 void (*dtor)(void *), 61 void (*main)(void *), 62 struct thread_desc *(*get_thread)(void *), 63 void *this 61 64 ) { 62 // First suspend, once the thread arrives here,63 // the function pointer to main can be invalidated without risk64 __suspend_internal();65 // First suspend, once the thread arrives here, 66 // the function pointer to main can be invalidated without risk 67 __suspend_internal(); 65 68 66 // Fetch the thread handle from the user defined thread structure67 struct thread_desc* thrd = get_thread( this );69 // Fetch the thread handle from the user defined thread structure 70 struct thread_desc* thrd = get_thread( this ); 68 71 69 // Officially start the thread by enabling preemption70 enable_interrupts( __cfaabi_dbg_ctx);72 // Officially start the thread by enabling preemption 73 enable_interrupts( DEBUG_CTX ); 71 74 72 // Call the main of the thread73 main( this );75 // Call the main of the thread 76 main( this ); 74 77 75 // To exit a thread we must :76 // 1 - Mark it as halted77 // 2 - Leave its monitor78 // 3 - Disable the interupts79 // 4 - Final suspend80 // The order of these 4 operations is very important81 //Final suspend, should never return82 __leave_thread_monitor( thrd );83 abortf("Resumed dead thread");78 // To exit a thread we must : 79 // 1 - Mark it as halted 80 // 2 - Leave its monitor 81 // 3 - Disable the interupts 82 // 4 - Final suspend 83 // The order of these 4 operations is very important 84 //Final suspend, should never return 85 __leave_thread_monitor( thrd ); 86 abortf("Resumed dead thread"); 84 87 } 85 88 86 89 87 90 void CtxStart( 88 void (*main)(void *),89 struct coroutine_desc *(*get_coroutine)(void *),90 void *this,91 void (*invoke)(void *)91 void (*main)(void *), 92 struct coroutine_desc *(*get_coroutine)(void *), 93 void *this, 94 void (*invoke)(void *) 92 95 ) { 93 struct coStack_t* stack = &get_coroutine( this )->stack; 96 // LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (main %p) to invoke (%p) from start (%p)\n", this, main, invoke, CtxStart); 97 98 struct coStack_t* stack = &get_coroutine( this )->stack; 94 99 95 100 #if defined( __i386__ ) … … 98 103 void *fixedRegisters[3]; // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant) 99 104 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls) 100 uint16_t fcw; // X97 FPU control word (preserved across function calls)105 uint16_t fcw; // X97 FPU control word (preserved across function calls) 101 106 void *rturn; // where to go on return from uSwitch 102 107 void *dummyReturn; // fake return compiler would have pushed on call to uInvoke … … 111 116 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this; // argument to invoke 112 117 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke; 113 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520114 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7118 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 119 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 115 120 116 121 #elif defined( __x86_64__ ) 117 122 118 struct FakeStack {119 void *fixedRegisters[5]; // fixed registers rbx, r12, r13, r14, r15120 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls)121 uint16_t fcw; // X97 FPU control word (preserved across function calls)122 void *rturn; // where to go on return from uSwitch123 void *dummyReturn; // NULL return address to provide proper alignment124 };123 struct FakeStack { 124 void *fixedRegisters[5]; // fixed registers rbx, r12, r13, r14, r15 125 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls) 126 uint16_t fcw; // X97 FPU control word (preserved across function calls) 127 void *rturn; // where to go on return from uSwitch 128 void *dummyReturn; // NULL return address to provide proper alignment 129 }; 125 130 126 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );127 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp131 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack ); 132 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp 128 133 129 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;130 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub;131 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this;132 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke;133 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520134 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7134 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL; 135 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub; 136 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this; 137 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke; 138 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 139 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 135 140 #else 136 #error Only __i386__ and __x86_64__ is supported for threads in cfa141 #error Only __i386__ and __x86_64__ is supported for threads in cfa 137 142 #endif 138 143 } -
src/libcfa/concurrency/kernel.c
rc13e8dc8 r9c35431 14 14 // 15 15 16 #include "libhdr.h" 17 16 18 //C Includes 17 19 #include <stddef.h> … … 148 150 149 151 this.runner = &runner; 150 __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner);152 LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner); 151 153 runner{ &this }; 152 154 } … … 154 156 void ^?{}(processor & this) { 155 157 if( ! this.do_terminate ) { 156 __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);158 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this); 157 159 this.do_terminate = true; 158 160 P( this.terminated ); … … 179 181 processor * this = runner.proc; 180 182 181 __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this);183 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this); 182 184 183 185 { … … 185 187 preemption_scope scope = { this }; 186 188 187 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);189 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this); 188 190 189 191 thread_desc * readyThread = NULL; … … 211 213 } 212 214 213 __cfaabi_dbg_print_safe("Kernel : core %p stopping\n", this);215 LIB_DEBUG_PRINT_SAFE("Kernel : core %p stopping\n", this); 214 216 } 215 217 216 218 V( this->terminated ); 217 219 218 __cfaabi_dbg_print_safe("Kernel : core %p terminated\n", this);220 LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this); 219 221 } 220 222 … … 290 292 processorCtx_t proc_cor_storage = { proc, &info }; 291 293 292 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);294 LIB_DEBUG_PRINT_SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base); 293 295 294 296 //Set global state … … 297 299 298 300 //We now have a proper context from which to schedule threads 299 __cfaabi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);301 LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx); 300 302 301 303 // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't … … 308 310 309 311 // Main routine of the core returned, the core is now fully terminated 310 __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, proc->runner);312 LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner); 311 313 312 314 return NULL; … … 314 316 315 317 void start(processor * this) { 316 __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this);318 LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this); 317 319 318 320 pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this ); 319 321 320 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);322 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this); 321 323 } 322 324 … … 332 334 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 333 335 334 lock( this_processor->cltr->ready_queue_lock __cfaabi_dbg_ctx2 );336 lock( this_processor->cltr->ready_queue_lock DEBUG_CTX2 ); 335 337 append( this_processor->cltr->ready_queue, thrd ); 336 338 unlock( this_processor->cltr->ready_queue_lock ); … … 341 343 thread_desc * nextThread(cluster * this) { 342 344 verify( disable_preempt_count > 0 ); 343 lock( this->ready_queue_lock __cfaabi_dbg_ctx2 );345 lock( this->ready_queue_lock DEBUG_CTX2 ); 344 346 thread_desc * head = pop_head( this->ready_queue ); 345 347 unlock( this->ready_queue_lock ); … … 353 355 suspend(); 354 356 verify( disable_preempt_count > 0 ); 355 enable_interrupts( __cfaabi_dbg_ctx);357 enable_interrupts( DEBUG_CTX ); 356 358 } 357 359 … … 365 367 verify( disable_preempt_count > 0 ); 366 368 367 enable_interrupts( __cfaabi_dbg_ctx);369 enable_interrupts( DEBUG_CTX ); 368 370 } 369 371 … … 379 381 verify( disable_preempt_count > 0 ); 380 382 381 enable_interrupts( __cfaabi_dbg_ctx);383 enable_interrupts( DEBUG_CTX ); 382 384 } 383 385 … … 393 395 verify( disable_preempt_count > 0 ); 394 396 395 enable_interrupts( __cfaabi_dbg_ctx);397 enable_interrupts( DEBUG_CTX ); 396 398 } 397 399 … … 406 408 verify( disable_preempt_count > 0 ); 407 409 408 enable_interrupts( __cfaabi_dbg_ctx);410 enable_interrupts( DEBUG_CTX ); 409 411 } 410 412 … … 421 423 verify( disable_preempt_count > 0 ); 422 424 423 enable_interrupts( __cfaabi_dbg_ctx);425 enable_interrupts( DEBUG_CTX ); 424 426 } 425 427 … … 439 441 // Kernel boot procedures 440 442 void kernel_startup(void) { 441 __cfaabi_dbg_print_safe("Kernel : Starting\n");443 LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n"); 442 444 443 445 // Start by initializing the main thread … … 448 450 (*mainThread){ &info }; 449 451 450 __cfaabi_dbg_print_safe("Kernel : Main thread ready\n");452 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n"); 451 453 452 454 // Initialize the main cluster … … 454 456 (*mainCluster){}; 455 457 456 __cfaabi_dbg_print_safe("Kernel : main cluster ready\n");458 LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n"); 457 459 458 460 // Initialize the main processor and the main processor ctx … … 481 483 482 484 // THE SYSTEM IS NOW COMPLETELY RUNNING 483 __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n");484 485 enable_interrupts( __cfaabi_dbg_ctx);485 LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n"); 486 487 enable_interrupts( DEBUG_CTX ); 486 488 } 487 489 488 490 void kernel_shutdown(void) { 489 __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n");491 LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n"); 490 492 491 493 disable_interrupts(); … … 511 513 ^(mainThread){}; 512 514 513 __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");515 LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n"); 514 516 } 515 517 … … 521 523 // abort cannot be recursively entered by the same or different processors because all signal handlers return when 522 524 // the globalAbort flag is true. 523 lock( kernel_abort_lock __cfaabi_dbg_ctx2 );525 lock( kernel_abort_lock DEBUG_CTX2 ); 524 526 525 527 // first task to abort ? … … 546 548 547 549 int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->self_cor.name, thrd ); 548 __ cfaabi_dbg_bits_write( abort_text, len );550 __lib_debug_write( abort_text, len ); 549 551 550 552 if ( thrd != this_coroutine ) { 551 553 len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine->name, this_coroutine ); 552 __ cfaabi_dbg_bits_write( abort_text, len );554 __lib_debug_write( abort_text, len ); 553 555 } 554 556 else { 555 __ cfaabi_dbg_bits_write( ".\n", 2 );557 __lib_debug_write( ".\n", 2 ); 556 558 } 557 559 } 558 560 559 561 extern "C" { 560 void __ cfaabi_dbg_bits_acquire() {561 lock( kernel_debug_lock __cfaabi_dbg_ctx2 );562 } 563 564 void __ cfaabi_dbg_bits_release() {562 void __lib_debug_acquire() { 563 lock( kernel_debug_lock DEBUG_CTX2 ); 564 } 565 566 void __lib_debug_release() { 565 567 unlock( kernel_debug_lock ); 566 568 } … … 580 582 581 583 void P(semaphore & this) { 582 lock( this.lock __cfaabi_dbg_ctx2 );584 lock( this.lock DEBUG_CTX2 ); 583 585 this.count -= 1; 584 586 if ( this.count < 0 ) { … … 596 598 void V(semaphore & this) { 597 599 thread_desc * thrd = NULL; 598 lock( this.lock __cfaabi_dbg_ctx2 );600 lock( this.lock DEBUG_CTX2 ); 599 601 this.count += 1; 600 602 if ( this.count <= 0 ) { -
src/libcfa/concurrency/kernel_private.h
rc13e8dc8 r9c35431 16 16 #pragma once 17 17 18 #include "libhdr.h" 19 18 20 #include "kernel" 19 21 #include "thread" … … 28 30 void disable_interrupts(); 29 31 void enable_interrupts_noPoll(); 30 void enable_interrupts( __cfaabi_dbg_ctx_param);32 void enable_interrupts( DEBUG_CTX_PARAM ); 31 33 } 32 34 … … 37 39 disable_interrupts(); 38 40 ScheduleThread( thrd ); 39 enable_interrupts( __cfaabi_dbg_ctx);41 enable_interrupts( DEBUG_CTX ); 40 42 } 41 43 thread_desc * nextThread(cluster * this); -
src/libcfa/concurrency/monitor.c
rc13e8dc8 r9c35431 19 19 #include <inttypes.h> 20 20 21 #include "libhdr.h" 21 22 #include "kernel_private.h" 22 23 … … 90 91 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 91 92 // Lock the monitor spinlock 92 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );93 DO_LOCK( this->lock DEBUG_CTX2 ); 93 94 thread_desc * thrd = this_thread; 94 95 95 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);96 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); 96 97 97 98 if( !this->owner ) { … … 99 100 set_owner( this, thrd ); 100 101 101 __cfaabi_dbg_print_safe("Kernel : mon is free \n");102 LIB_DEBUG_PRINT_SAFE("Kernel : mon is free \n"); 102 103 } 103 104 else if( this->owner == thrd) { … … 105 106 this->recursion += 1; 106 107 107 __cfaabi_dbg_print_safe("Kernel : mon already owned \n");108 LIB_DEBUG_PRINT_SAFE("Kernel : mon already owned \n"); 108 109 } 109 110 else if( is_accepted( this, group) ) { … … 114 115 reset_mask( this ); 115 116 116 __cfaabi_dbg_print_safe("Kernel : mon accepts \n");117 LIB_DEBUG_PRINT_SAFE("Kernel : mon accepts \n"); 117 118 } 118 119 else { 119 __cfaabi_dbg_print_safe("Kernel : blocking \n");120 LIB_DEBUG_PRINT_SAFE("Kernel : blocking \n"); 120 121 121 122 // Some one else has the monitor, wait in line for it … … 123 124 BlockInternal( &this->lock ); 124 125 125 __cfaabi_dbg_print_safe("Kernel : %10p Entered mon %p\n", thrd, this);126 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered mon %p\n", thrd, this); 126 127 127 128 // BlockInternal will unlock spinlock, no need to unlock ourselves … … 129 130 } 130 131 131 __cfaabi_dbg_print_safe("Kernel : %10p Entered mon %p\n", thrd, this);132 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered mon %p\n", thrd, this); 132 133 133 134 // Release the lock and leave … … 138 139 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 139 140 // Lock the monitor spinlock 140 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );141 DO_LOCK( this->lock DEBUG_CTX2 ); 141 142 thread_desc * thrd = this_thread; 142 143 143 __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);144 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner); 144 145 145 146 146 147 if( !this->owner ) { 147 __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this);148 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying free mon %p\n", this); 148 149 149 150 // No one has the monitor, just take it … … 163 164 __monitor_group_t group = { &this, 1, func }; 164 165 if( is_accepted( this, group) ) { 165 __cfaabi_dbg_print_safe("Kernel : mon accepts dtor, block and signal it \n");166 LIB_DEBUG_PRINT_SAFE("Kernel : mon accepts dtor, block and signal it \n"); 166 167 167 168 // Wake the thread that is waiting for this … … 182 183 } 183 184 else { 184 __cfaabi_dbg_print_safe("Kernel : blocking \n");185 LIB_DEBUG_PRINT_SAFE("Kernel : blocking \n"); 185 186 186 187 wait_ctx( this_thread, 0 ) … … 195 196 } 196 197 197 __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this);198 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying %p\n", this); 198 199 199 200 } … … 202 203 void __leave_monitor_desc( monitor_desc * this ) { 203 204 // Lock the monitor spinlock, DO_LOCK to reduce contention 204 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );205 206 __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);205 DO_LOCK( this->lock DEBUG_CTX2 ); 206 207 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); 207 208 208 209 verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this ); … … 214 215 // it means we don't need to do anything 215 216 if( this->recursion != 0) { 216 __cfaabi_dbg_print_safe("Kernel : recursion still %d\n", this->recursion);217 LIB_DEBUG_PRINT_SAFE("Kernel : recursion still %d\n", this->recursion); 217 218 unlock( this->lock ); 218 219 return; … … 231 232 // Leave single monitor for the last time 232 233 void __leave_dtor_monitor_desc( monitor_desc * this ) { 233 __cfaabi_dbg_debug_do(234 LIB_DEBUG_DO( 234 235 if( this_thread != this->owner ) { 235 236 abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner); … … 248 249 249 250 // Lock the monitor now 250 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );251 DO_LOCK( this->lock DEBUG_CTX2 ); 251 252 252 253 disable_interrupts(); … … 307 308 (this_thread->monitors){m, count, func}; 308 309 309 // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count);310 // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count); 310 311 311 312 // Enter the monitors in order … … 313 314 enter( group ); 314 315 315 // __cfaabi_dbg_print_safe("MGUARD : entered\n");316 // LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n"); 316 317 } 317 318 … … 319 320 // Dtor for monitor guard 320 321 void ^?{}( monitor_guard_t & this ) { 321 // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count);322 // LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count); 322 323 323 324 // Leave the monitors in order 324 325 leave( this.m, this.count ); 325 326 326 // __cfaabi_dbg_print_safe("MGUARD : left\n");327 // LIB_DEBUG_PRINT_SAFE("MGUARD : left\n"); 327 328 328 329 // Restore thread context … … 429 430 430 431 //Some more checking in debug 431 __cfaabi_dbg_debug_do(432 LIB_DEBUG_DO( 432 433 thread_desc * this_thrd = this_thread; 433 434 if ( this.monitor_count != this_thrd->monitors.size ) { … … 486 487 set_owner( monitors, count, signallee ); 487 488 488 __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );489 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee ); 489 490 490 491 //Everything is ready to go to sleep … … 495 496 496 497 497 __cfaabi_dbg_print_buffer_local( "Kernel : signal_block returned\n" );498 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : signal_block returned\n" ); 498 499 499 500 //We are back, restore the masks and recursions … … 534 535 __lock_size_t actual_count = aggregate( mon_storage, mask ); 535 536 536 __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);537 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max); 537 538 538 539 if(actual_count == 0) return; 539 540 540 __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n");541 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n"); 541 542 542 543 // Create storage for monitor context … … 555 556 __acceptable_t& accepted = mask[index]; 556 557 if( accepted.is_dtor ) { 557 __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n");558 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n"); 558 559 verifyf( accepted.size == 1, "ERROR: Accepted dtor has more than 1 mutex parameter." ); 559 560 … … 567 568 } 568 569 else { 569 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n");570 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n"); 570 571 571 572 // Create the node specific to this wait operation … … 575 576 monitor_save; 576 577 577 __cfaabi_dbg_print_buffer_local( "Kernel : baton of %d monitors : ", count );578 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : baton of %d monitors : ", count ); 578 579 #ifdef __CFA_DEBUG_PRINT__ 579 580 for( int i = 0; i < count; i++) { 580 __cfaabi_dbg_print_buffer_local( "%p %p ", monitors[i], monitors[i]->signal_stack.top );581 LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top ); 581 582 } 582 583 #endif 583 __cfaabi_dbg_print_buffer_local( "\n");584 LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n"); 584 585 585 586 // Set the owners to be the next thread … … 592 593 monitor_restore; 593 594 594 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n");595 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n"); 595 596 } 596 597 597 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);598 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted); 598 599 return; 599 600 } … … 602 603 603 604 if( duration == 0 ) { 604 __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n");605 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n"); 605 606 606 607 unlock_all( locks, count ); 607 608 608 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);609 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted); 609 610 return; 610 611 } … … 613 614 verifyf( duration < 0, "Timeout on waitfor statments not supported yet."); 614 615 615 __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n");616 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n"); 616 617 617 618 // Create the node specific to this wait operation … … 635 636 monitor_restore; 636 637 637 __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n");638 639 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);638 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n"); 639 640 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted); 640 641 } 641 642 … … 644 645 645 646 static inline void set_owner( monitor_desc * this, thread_desc * owner ) { 646 // __cfaabi_dbg_print_safe("Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );647 // LIB_DEBUG_PRINT_SAFE("Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner ); 647 648 648 649 //Pass the monitor appropriately … … 676 677 static inline thread_desc * next_thread( monitor_desc * this ) { 677 678 //Check the signaller stack 678 __cfaabi_dbg_print_safe("Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top);679 LIB_DEBUG_PRINT_SAFE("Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top); 679 680 __condition_criterion_t * urgent = pop( this->signal_stack ); 680 681 if( urgent ) { … … 728 729 for( __lock_size_t i = 0; i < count; i++) { 729 730 (criteria[i]){ monitors[i], waiter }; 730 __cfaabi_dbg_print_safe( "Kernel : target %p = %p\n", criteria[i].target, &criteria[i] );731 LIB_DEBUG_PRINT_SAFE( "Kernel : target %p = %p\n", criteria[i].target, &criteria[i] ); 731 732 push( criteria[i].target->signal_stack, &criteria[i] ); 732 733 } … … 737 738 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) { 738 739 for( __lock_size_t i = 0; i < count; i++ ) { 739 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );740 DO_LOCK( *locks[i] DEBUG_CTX2 ); 740 741 } 741 742 } … … 744 745 for( __lock_size_t i = 0; i < count; i++ ) { 745 746 __spinlock_t * l = &source[i]->lock; 746 DO_LOCK( *l __cfaabi_dbg_ctx2 );747 DO_LOCK( *l DEBUG_CTX2 ); 747 748 if(locks) locks[i] = l; 748 749 } … … 802 803 for( int i = 0; i < count; i++ ) { 803 804 804 // __cfaabi_dbg_print_safe( "Checking %p for %p\n", &criteria[i], target );805 // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target ); 805 806 if( &criteria[i] == target ) { 806 807 criteria[i].ready = true; 807 // __cfaabi_dbg_print_safe( "True\n" );808 // LIB_DEBUG_PRINT_SAFE( "True\n" ); 808 809 } 809 810 … … 811 812 } 812 813 813 __cfaabi_dbg_print_safe( "Kernel : Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );814 LIB_DEBUG_PRINT_SAFE( "Kernel : Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL ); 814 815 return ready2run ? node->waiting_thread : NULL; 815 816 } … … 818 819 thread_desc * thrd = this_thread; 819 820 if( !this.monitors ) { 820 // __cfaabi_dbg_print_safe("Branding\n");821 // LIB_DEBUG_PRINT_SAFE("Branding\n"); 821 822 assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data ); 822 823 this.monitor_count = thrd->monitors.size; -
src/libcfa/concurrency/preemption.c
rc13e8dc8 r9c35431 14 14 // 15 15 16 #include "libhdr.h" 16 17 #include "preemption.h" 17 18 … … 147 148 //============================================================================================= 148 149 149 __cfaabi_dbg_debug_do( static thread_local void * last_interrupt = 0; )150 LIB_DEBUG_DO( static thread_local void * last_interrupt = 0; ) 150 151 151 152 extern "C" { … … 158 159 // Enable interrupts by decrementing the counter 159 160 // If counter reaches 0, execute any pending CtxSwitch 160 void enable_interrupts( __cfaabi_dbg_ctx_param) {161 void enable_interrupts( DEBUG_CTX_PARAM ) { 161 162 processor * proc = this_processor; // Cache the processor now since interrupts can start happening after the atomic add 162 163 thread_desc * thrd = this_thread; // Cache the thread now since interrupts can start happening after the atomic add … … 172 173 173 174 // For debugging purposes : keep track of the last person to enable the interrupts 174 __cfaabi_dbg_debug_do( proc->last_enable = caller; )175 LIB_DEBUG_DO( proc->last_enable = caller; ) 175 176 } 176 177 … … 232 233 // Called from kernel_startup 233 234 void kernel_start_preemption() { 234 __cfaabi_dbg_print_safe("Kernel : Starting preemption\n");235 LIB_DEBUG_PRINT_SAFE("Kernel : Starting preemption\n"); 235 236 236 237 // Start with preemption disabled until ready … … 254 255 // Called from kernel_shutdown 255 256 void kernel_stop_preemption() { 256 __cfaabi_dbg_print_safe("Kernel : Preemption stopping\n");257 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopping\n"); 257 258 258 259 // Block all signals since we are already shutting down … … 270 271 // Preemption is now fully stopped 271 272 272 __cfaabi_dbg_print_safe("Kernel : Preemption stopped\n");273 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopped\n"); 273 274 } 274 275 … … 296 297 // Receives SIGUSR1 signal and causes the current thread to yield 297 298 void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) { 298 __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )299 LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); ) 299 300 300 301 // Check if it is safe to preempt here … … 345 346 assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int); 346 347 347 // __cfaabi_dbg_print_safe("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );348 // LIB_DEBUG_PRINT_SAFE("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int ); 348 349 // Switch on the code (a.k.a. the sender) to 349 350 switch( info.si_code ) … … 353 354 case SI_TIMER: 354 355 case SI_KERNEL: 355 // __cfaabi_dbg_print_safe("Kernel : Preemption thread tick\n");356 lock( event_kernel->lock __cfaabi_dbg_ctx2 );356 // LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread tick\n"); 357 lock( event_kernel->lock DEBUG_CTX2 ); 357 358 tick_preemption(); 358 359 unlock( event_kernel->lock ); … … 367 368 368 369 EXIT: 369 __cfaabi_dbg_print_safe("Kernel : Preemption thread stopping\n");370 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread stopping\n"); 370 371 return NULL; 371 372 } … … 379 380 380 381 if ( sigaction( sig, &act, NULL ) == -1 ) { 381 __cfaabi_dbg_print_buffer_decl(382 LIB_DEBUG_PRINT_BUFFER_DECL( 382 383 " __kernel_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n", 383 384 sig, handler, flags, errno, strerror( errno ) … … 396 397 397 398 if ( sigaction( sig, &act, NULL ) == -1 ) { 398 __cfaabi_dbg_print_buffer_decl(399 LIB_DEBUG_PRINT_BUFFER_DECL( 399 400 " __kernel_sigdefault( sig:%d ), problem reseting signal handler, error(%d) %s.\n", 400 401 sig, errno, strerror( errno ) … … 408 409 //============================================================================================= 409 410 410 __cfaabi_dbg_debug_do(411 LIB_DEBUG_DO( 411 412 static void __kernel_backtrace( int start ) { 412 413 // skip first N stack frames … … 475 476 476 477 // void sigHandler_segv( __CFA_SIGPARMS__ ) { 477 // __cfaabi_dbg_debug_do(478 // LIB_DEBUG_DO( 478 479 // #ifdef __USE_STREAM__ 479 480 // serr | "*CFA runtime error* program cfa-cpp terminated with" … … 492 493 // void sigHandler_abort( __CFA_SIGPARMS__ ) { 493 494 // // skip first 6 stack frames 494 // __cfaabi_dbg_debug_do( __kernel_backtrace( 6 ); )495 // LIB_DEBUG_DO( __kernel_backtrace( 6 ); ) 495 496 496 497 // // reset default signal handler -
src/libcfa/concurrency/thread.c
rc13e8dc8 r9c35431 17 17 18 18 #include "kernel_private.h" 19 #include "libhdr.h" 19 20 20 21 #define __CFA_INVOKE_PRIVATE__ … … 71 72 thrd_c->last = this_coroutine; 72 73 73 // __cfaabi_dbg_print_safe("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);74 // LIB_DEBUG_PRINT_SAFE("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 74 75 75 76 disable_interrupts(); … … 81 82 82 83 ScheduleThread(thrd_h); 83 enable_interrupts( __cfaabi_dbg_ctx);84 enable_interrupts( DEBUG_CTX ); 84 85 } 85 86 -
src/libcfa/exception.c
rc13e8dc8 r9c35431 23 23 #include <stdio.h> 24 24 #include <unwind.h> 25 #include < bits/debug.h>25 #include <libhdr/libdebug.h> 26 26 27 27 // FIX ME: temporary hack to keep ARM build working … … 37 37 38 38 // Base exception vtable is abstract, you should not have base exceptions. 39 struct __cfa abi_ehm__base_exception_t_vtable40 ___cfa abi_ehm__base_exception_t_vtable_instance = {39 struct __cfaehm__base_exception_t_vtable 40 ___cfaehm__base_exception_t_vtable_instance = { 41 41 .parent = NULL, 42 42 .size = 0, … … 49 49 // Temperary global exception context. Does not work with concurency. 50 50 struct exception_context_t { 51 struct __cfa abi_ehm__try_resume_node * top_resume;52 struct __cfa abi_ehm__try_resume_node * current_resume;51 struct __cfaehm__try_resume_node * top_resume; 52 struct __cfaehm__try_resume_node * current_resume; 53 53 54 54 exception * current_exception; … … 78 78 // RESUMPTION ================================================================ 79 79 80 void __cfa abi_ehm__throw_resume(exception * except) {81 82 __cfaabi_dbg_print_safe("Throwing resumption exception\n");83 84 struct __cfa abi_ehm__try_resume_node * original_head = shared_stack.current_resume;85 struct __cfa abi_ehm__try_resume_node * current =80 void __cfaehm__throw_resume(exception * except) { 81 82 LIB_DEBUG_PRINT_SAFE("Throwing resumption exception\n"); 83 84 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; 85 struct __cfaehm__try_resume_node * current = 86 86 (original_head) ? original_head->next : shared_stack.top_resume; 87 87 … … 94 94 } 95 95 96 __cfaabi_dbg_print_safe("Unhandled exception\n");96 LIB_DEBUG_PRINT_SAFE("Unhandled exception\n"); 97 97 shared_stack.current_resume = original_head; 98 98 99 99 // Fall back to termination: 100 __cfa abi_ehm__throw_terminate(except);100 __cfaehm__throw_terminate(except); 101 101 // TODO: Default handler for resumption. 102 102 } … … 105 105 // hook has to be added after the node is built but before it is made the top node. 106 106 107 void __cfa abi_ehm__try_resume_setup(struct __cfaabi_ehm__try_resume_node * node,107 void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node, 108 108 _Bool (*handler)(exception * except)) { 109 109 node->next = shared_stack.top_resume; … … 112 112 } 113 113 114 void __cfa abi_ehm__try_resume_cleanup(struct __cfaabi_ehm__try_resume_node * node) {114 void __cfaehm__try_resume_cleanup(struct __cfaehm__try_resume_node * node) { 115 115 shared_stack.top_resume = node->next; 116 116 } … … 122 122 // May have to move to cfa for constructors and destructors (references). 123 123 124 struct __cfa abi_ehm__node {125 struct __cfa abi_ehm__node * next;124 struct __cfaehm__node { 125 struct __cfaehm__node * next; 126 126 }; 127 127 128 128 #define NODE_TO_EXCEPT(node) ((exception *)(1 + (node))) 129 #define EXCEPT_TO_NODE(except) ((struct __cfa abi_ehm__node *)(except) - 1)129 #define EXCEPT_TO_NODE(except) ((struct __cfaehm__node *)(except) - 1) 130 130 131 131 // Creates a copy of the indicated exception and sets current_exception to it. 132 static void __cfa abi_ehm__allocate_exception( exception * except ) {132 static void __cfaehm__allocate_exception( exception * except ) { 133 133 struct exception_context_t * context = this_exception_context(); 134 134 135 135 // Allocate memory for the exception. 136 struct __cfa abi_ehm__node * store = malloc(137 sizeof( struct __cfa abi_ehm__node ) + except->virtual_table->size );136 struct __cfaehm__node * store = malloc( 137 sizeof( struct __cfaehm__node ) + except->virtual_table->size ); 138 138 139 139 if ( ! store ) { … … 151 151 152 152 // Delete the provided exception, unsetting current_exception if relivant. 153 static void __cfa abi_ehm__delete_exception( exception * except ) {153 static void __cfaehm__delete_exception( exception * except ) { 154 154 struct exception_context_t * context = this_exception_context(); 155 155 156 __cfaabi_dbg_print_safe("Deleting Exception\n");156 LIB_DEBUG_PRINT_SAFE("Deleting Exception\n"); 157 157 158 158 // Remove the exception from the list. 159 struct __cfa abi_ehm__node * to_free = EXCEPT_TO_NODE(except);160 struct __cfa abi_ehm__node * node;159 struct __cfaehm__node * to_free = EXCEPT_TO_NODE(except); 160 struct __cfaehm__node * node; 161 161 162 162 if ( context->current_exception == except ) { … … 178 178 179 179 // If this isn't a rethrow (*except==0), delete the provided exception. 180 void __cfa abi_ehm__cleanup_terminate( void * except ) {181 if ( *(void**)except ) __cfa abi_ehm__delete_exception( *(exception**)except );180 void __cfaehm__cleanup_terminate( void * except ) { 181 if ( *(void**)except ) __cfaehm__delete_exception( *(exception**)except ); 182 182 } 183 183 … … 202 202 203 203 // The exception that is being thrown must already be stored. 204 __attribute__((noreturn)) void __cfa abi_ehm__begin_unwind(void) {204 __attribute__((noreturn)) void __cfaehm__begin_unwind(void) { 205 205 if ( ! this_exception_context()->current_exception ) { 206 206 printf("UNWIND ERROR missing exception in begin unwind\n"); … … 233 233 } 234 234 235 void __cfa abi_ehm__throw_terminate( exception * val ) {236 __cfaabi_dbg_print_safe("Throwing termination exception\n");237 238 __cfa abi_ehm__allocate_exception( val );239 __cfa abi_ehm__begin_unwind();240 } 241 242 void __cfa abi_ehm__rethrow_terminate(void) {243 __cfaabi_dbg_print_safe("Rethrowing termination exception\n");244 245 __cfa abi_ehm__begin_unwind();235 void __cfaehm__throw_terminate( exception * val ) { 236 LIB_DEBUG_PRINT_SAFE("Throwing termination exception\n"); 237 238 __cfaehm__allocate_exception( val ); 239 __cfaehm__begin_unwind(); 240 } 241 242 void __cfaehm__rethrow_terminate(void) { 243 LIB_DEBUG_PRINT_SAFE("Rethrowing termination exception\n"); 244 245 __cfaehm__begin_unwind(); 246 246 } 247 247 … … 254 254 { 255 255 256 // __cfaabi_dbg_print_safe("CFA: 0x%lx\n", _Unwind_GetCFA(context));257 __cfaabi_dbg_print_safe("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);256 //LIB_DEBUG_PRINT_SAFE("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 257 LIB_DEBUG_PRINT_SAFE("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context); 258 258 259 259 // If we've reached the end of the stack then there is nothing much we can do... … … 261 261 262 262 if (actions & _UA_SEARCH_PHASE) { 263 __cfaabi_dbg_print_safe(" lookup phase");263 LIB_DEBUG_PRINT_SAFE(" lookup phase"); 264 264 } 265 265 else if (actions & _UA_CLEANUP_PHASE) { 266 __cfaabi_dbg_print_safe(" cleanup phase");266 LIB_DEBUG_PRINT_SAFE(" cleanup phase"); 267 267 } 268 268 // Just in case, probably can't actually happen … … 307 307 void * ep = (void*)lsd_info.Start + callsite_start + callsite_len; 308 308 void * ip = (void*)instruction_ptr; 309 __cfaabi_dbg_print_safe("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);309 LIB_DEBUG_PRINT_SAFE("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip); 310 310 #endif // __CFA_DEBUG_PRINT__ 311 311 continue; … … 346 346 347 347 // Get a function pointer from the relative offset and call it 348 // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 348 // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 349 349 350 350 _Unwind_Reason_Code (*matcher)(exception *) = … … 357 357 // Based on the return value, check if we matched the exception 358 358 if( ret == _URC_HANDLER_FOUND) { 359 __cfaabi_dbg_print_safe(" handler found\n");359 LIB_DEBUG_PRINT_SAFE(" handler found\n"); 360 360 } else { 361 __cfaabi_dbg_print_safe(" no handler\n");361 LIB_DEBUG_PRINT_SAFE(" no handler\n"); 362 362 } 363 363 return ret; … … 365 365 366 366 // This is only a cleanup handler, ignore it 367 __cfaabi_dbg_print_safe(" no action");367 LIB_DEBUG_PRINT_SAFE(" no action"); 368 368 } 369 369 else if (actions & _UA_CLEANUP_PHASE) { … … 385 385 _Unwind_SetIP( context, ((lsd_info.LPStart) + (callsite_landing_pad)) ); 386 386 387 __cfaabi_dbg_print_safe(" action\n");387 LIB_DEBUG_PRINT_SAFE(" action\n"); 388 388 389 389 // Return have some action to run … … 393 393 394 394 // Nothing to do, move along 395 __cfaabi_dbg_print_safe(" no landing pad");395 LIB_DEBUG_PRINT_SAFE(" no landing pad"); 396 396 } 397 397 // No handling found 398 __cfaabi_dbg_print_safe(" table end reached\n");398 LIB_DEBUG_PRINT_SAFE(" table end reached\n"); 399 399 400 400 UNWIND: 401 __cfaabi_dbg_print_safe(" unwind\n");401 LIB_DEBUG_PRINT_SAFE(" unwind\n"); 402 402 403 403 // Keep unwinding the stack … … 408 408 // libcfa but there is one problem left, see the exception table for details 409 409 __attribute__((noinline)) 410 void __cfa abi_ehm__try_terminate(void (*try_block)(),410 void __cfaehm__try_terminate(void (*try_block)(), 411 411 void (*catch_block)(int index, exception * except), 412 412 __attribute__((unused)) int (*match_block)(exception * except)) { … … 466 466 // Body uses language specific data and therefore could be modified arbitrarily 467 467 ".LLSDACSBCFA2:\n" // BODY start 468 " .uleb128 .TRYSTART-__cfa abi_ehm__try_terminate\n" // Handled area start (relative to start of function)468 " .uleb128 .TRYSTART-__cfaehm__try_terminate\n" // Handled area start (relative to start of function) 469 469 " .uleb128 .TRYEND-.TRYSTART\n" // Handled area length 470 " .uleb128 .CATCH-__cfa abi_ehm__try_terminate\n" // Hanlder landing pad adress (relative to start of function)470 " .uleb128 .CATCH-__cfaehm__try_terminate\n" // Hanlder landing pad adress (relative to start of function) 471 471 " .uleb128 1\n" // Action code, gcc seems to use always 0 472 472 ".LLSDACSECFA2:\n" // BODY end 473 473 " .text\n" // TABLE footer 474 " .size __cfa abi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n"474 " .size __cfaehm__try_terminate, .-__cfaehm__try_terminate\n" 475 475 " .ident \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n" 476 476 // " .section .note.GNU-stack,\"x\",@progbits\n" -
src/libcfa/exception.h
rc13e8dc8 r9c35431 21 21 #endif 22 22 23 struct __cfa abi_ehm__base_exception_t;24 typedef struct __cfa abi_ehm__base_exception_t exception;25 struct __cfa abi_ehm__base_exception_t_vtable {26 const struct __cfa abi_ehm__base_exception_t_vtable * parent;23 struct __cfaehm__base_exception_t; 24 typedef struct __cfaehm__base_exception_t exception; 25 struct __cfaehm__base_exception_t_vtable { 26 const struct __cfaehm__base_exception_t_vtable * parent; 27 27 size_t size; 28 void (*copy)(struct __cfa abi_ehm__base_exception_t *this,29 struct __cfa abi_ehm__base_exception_t * other);30 void (*free)(struct __cfa abi_ehm__base_exception_t *this);31 const char * (*msg)(struct __cfa abi_ehm__base_exception_t *this);28 void (*copy)(struct __cfaehm__base_exception_t *this, 29 struct __cfaehm__base_exception_t * other); 30 void (*free)(struct __cfaehm__base_exception_t *this); 31 const char * (*msg)(struct __cfaehm__base_exception_t *this); 32 32 }; 33 struct __cfa abi_ehm__base_exception_t {34 struct __cfa abi_ehm__base_exception_t_vtable const * virtual_table;33 struct __cfaehm__base_exception_t { 34 struct __cfaehm__base_exception_t_vtable const * virtual_table; 35 35 }; 36 extern struct __cfa abi_ehm__base_exception_t_vtable37 ___cfa abi_ehm__base_exception_t_vtable_instance;36 extern struct __cfaehm__base_exception_t_vtable 37 ___cfaehm__base_exception_t_vtable_instance; 38 38 39 39 40 40 // Used in throw statement translation. 41 void __cfa abi_ehm__throw_terminate(exception * except) __attribute__((noreturn));42 void __cfa abi_ehm__rethrow_terminate() __attribute__((noreturn));43 void __cfa abi_ehm__throw_resume(exception * except);41 void __cfaehm__throw_terminate(exception * except) __attribute__((noreturn)); 42 void __cfaehm__rethrow_terminate() __attribute__((noreturn)); 43 void __cfaehm__throw_resume(exception * except); 44 44 45 45 // Function catches termination exceptions. 46 void __cfa abi_ehm__try_terminate(46 void __cfaehm__try_terminate( 47 47 void (*try_block)(), 48 48 void (*catch_block)(int index, exception * except), … … 50 50 51 51 // Clean-up the exception in catch blocks. 52 void __cfa abi_ehm__cleanup_terminate(void * except);52 void __cfaehm__cleanup_terminate(void * except); 53 53 54 54 // Data structure creates a list of resume handlers. 55 struct __cfa abi_ehm__try_resume_node {56 struct __cfa abi_ehm__try_resume_node * next;55 struct __cfaehm__try_resume_node { 56 struct __cfaehm__try_resume_node * next; 57 57 _Bool (*handler)(exception * except); 58 58 }; 59 59 60 60 // These act as constructor and destructor for the resume node. 61 void __cfa abi_ehm__try_resume_setup(62 struct __cfa abi_ehm__try_resume_node * node,61 void __cfaehm__try_resume_setup( 62 struct __cfaehm__try_resume_node * node, 63 63 _Bool (*handler)(exception * except)); 64 void __cfa abi_ehm__try_resume_cleanup(65 struct __cfa abi_ehm__try_resume_node * node);64 void __cfaehm__try_resume_cleanup( 65 struct __cfaehm__try_resume_node * node); 66 66 67 67 // Check for a standard way to call fake deconstructors. 68 struct __cfa abi_ehm__cleanup_hook {};68 struct __cfaehm__cleanup_hook {}; 69 69 70 70 #ifdef __cforall -
src/libcfa/interpose.c
rc13e8dc8 r9c35431 24 24 } 25 25 26 #include " bits/debug.h"27 #include " bits/defs.h"26 #include "libhdr/libdebug.h" 27 #include "libhdr/libtools.h" 28 28 #include "startup.h" 29 29 … … 69 69 __typeof__( exit ) libc_exit __attribute__(( noreturn )); 70 70 __typeof__( abort ) libc_abort __attribute__(( noreturn )); 71 72 // #define INIT_REALRTN( x, ver ) libc_##x = (__typeof__(libc_##x))interpose_symbol( #x, ver ) 71 73 72 74 forall(dtype T) … … 125 127 va_end( args ); 126 128 127 __ cfaabi_dbg_bits_write( abort_text, len );128 __ cfaabi_dbg_bits_write( "\n", 1 );129 __lib_debug_write( abort_text, len ); 130 __lib_debug_write( "\n", 1 ); 129 131 } 130 132 131 133 len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld)\n", (long int)getpid() ); // use UNIX pid (versus getPid) 132 __ cfaabi_dbg_bits_write( abort_text, len );134 __lib_debug_write( abort_text, len ); 133 135 134 136 -
src/libcfa/stdhdr/assert.h
rc13e8dc8 r9c35431 30 30 #endif 31 31 32 #if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__))33 #define verify(x) assert(x)34 #define verifyf(x, ...) assertf(x, __VA_ARGS__)35 #else36 #define verify(x)37 #define verifyf(x, ...)38 #endif39 40 32 #ifdef __cforall 41 33 } // extern "C" -
src/prelude/builtins.c
rc13e8dc8 r9c35431 16 16 // exception implementation 17 17 18 typedef unsigned long long __cfaabi_ abi_exception_type_t;18 typedef unsigned long long __cfaabi_exception_type_t; 19 19 20 20 #include "../libcfa/virtual.h" … … 80 80 } // ?\? 81 81 82 // FIXME (x \ (unsigned long int)y) relies on X ?\?(T, unsigned long) a function that is neither 83 // defined, nor passed as an assertion parameter. Without user-defined conversions, cannot specify 84 // X as a type that casts to double, yet it doesn't make sense to write functions with that type 82 // FIXME (x \ (unsigned long int)y) relies on X ?\?(T, unsigned long) a function that is neither 83 // defined, nor passed as an assertion parameter. Without user-defined conversions, cannot specify 84 // X as a type that casts to double, yet it doesn't make sense to write functions with that type 85 85 // signature where X is double. 86 86 -
src/tests/.expect/declarationErrors.txt
rc13e8dc8 r9c35431 7 7 declarationErrors.c:19:1 error: duplicate static in declaration of x4: static const volatile instance of const volatile struct __anonymous0 8 8 with members 9 i: int10 9 with body 11 10 … … 13 12 declarationErrors.c:20:1 error: duplicate const, duplicate static, duplicate volatile in declaration of x5: static const volatile instance of const volatile struct __anonymous1 14 13 with members 15 i: int16 14 with body 17 15 -
src/tests/Makefile.am
rc13e8dc8 r9c35431 20 20 21 21 if BUILD_CONCURRENCY 22 concurrent= 22 concurrent = yes 23 quick_test += coroutine thread monitor 24 concurrent_test = \ 25 coroutine \ 26 fmtLines \ 27 pingpong \ 28 prodcons \ 29 thread \ 30 matrixSum \ 31 monitor \ 32 multi-monitor \ 33 boundedBuffer \ 34 preempt \ 35 sched-int-block \ 36 sched-int-disjoint \ 37 sched-int-wait \ 38 sched-ext-barge \ 39 sched-ext-dtor \ 40 sched-ext-else \ 41 sched-ext-parse \ 42 sched-ext-recurse \ 43 sched-ext-statment \ 44 sched-ext-when 23 45 else 24 concurrent='-Econcurrent' 46 concurrent=no 47 concurrent_test= 25 48 endif 26 49 … … 39 62 endif 40 63 41 TEST_FLAGS = $(if $(test), 2> $(test), )64 TEST_FLAGS = $(if $(test), 2> .err/${@}.log, ) 42 65 AM_CFLAGS = ${TEST_FLAGS} ${BUILD_FLAGS} 43 66 CC = @CFA_BINDIR@/@CFA_NAME@ … … 47 70 48 71 fstream_test_SOURCES = fstream_test.c 49 fstream_test_CFLAGS = $(if $(test), 2>> $(test), ) ${BUILD_FLAGS}72 fstream_test_CFLAGS = $(if $(test), 2>> .err/fstream_test.log, ) ${BUILD_FLAGS} 50 73 51 74 vector_test_SOURCES = vector/vector_int.c vector/array.c vector/vector_test.c 52 vector_test_CFLAGS = $(if $(test), 2>> $(test), ) ${BUILD_FLAGS}75 vector_test_CFLAGS = $(if $(test), 2>> .err/vector_test.log, ) ${BUILD_FLAGS} 53 76 54 77 avl_test_SOURCES = avltree/avl_test.c avltree/avl0.c avltree/avl1.c avltree/avl2.c avltree/avl3.c avltree/avl4.c avltree/avl-private.c 55 avl_test_CFLAGS = $(if $(test), 2>> $(test), ) ${BUILD_FLAGS}78 avl_test_CFLAGS = $(if $(test), 2>> .err/avl_test.log, ) ${BUILD_FLAGS} 56 79 57 80 all-local : 58 @+python test.py --debug=${debug} ${concurrent} ${quick_test}81 @+python test.py --debug=${debug} --concurrent=${concurrent} ${quick_test} 59 82 60 83 all-tests : 61 @+python test.py --all --debug=${debug} ${concurrent} # '@' => do not echo command (SILENT), '+' => allows recursive make from within python program84 @+python test.py --all --debug=${debug} --concurrent=${concurrent} # '@' => do not echo command (SILENT), '+' => allows recursive make from within python program 62 85 63 86 clean-local : … … 65 88 66 89 list : 67 @+python test.py --list ${concurrent}90 @+python test.py --list --concurrent=${concurrent} 68 91 69 92 concurrency : 70 @+python test.py --debug=${debug} ${concurrent} ${concurrent_test}93 @+python test.py --debug=${debug} --concurrent=${concurrent} ${concurrent_test} 71 94 72 95 .dummy : .dummy.c @CFA_BINDIR@/@CFA_NAME@ -
src/tests/Makefile.in
rc13e8dc8 r9c35431 91 91 build_triplet = @build@ 92 92 host_triplet = @host@ 93 @BUILD_DEBUG_FALSE@am__append_1 = -nodebug 94 @BUILD_DEBUG_TRUE@@BUILD_RELEASE_FALSE@am__append_2 = -debug 95 @BUILD_DEBUG_TRUE@@BUILD_RELEASE_TRUE@am__append_3 = ${DEBUG_FLAGS} 93 @BUILD_CONCURRENCY_TRUE@am__append_1 = coroutine thread monitor 94 @BUILD_DEBUG_FALSE@am__append_2 = -nodebug 95 @BUILD_DEBUG_TRUE@@BUILD_RELEASE_FALSE@am__append_3 = -debug 96 @BUILD_DEBUG_TRUE@@BUILD_RELEASE_TRUE@am__append_4 = ${DEBUG_FLAGS} 96 97 EXTRA_PROGRAMS = fstream_test$(EXEEXT) vector_test$(EXEEXT) \ 97 98 avl_test$(EXEEXT) … … 313 314 top_srcdir = @top_srcdir@ 314 315 debug = yes 315 quick_test = vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once attributes 316 @BUILD_CONCURRENCY_FALSE@concurrent = '-Econcurrent' 317 @BUILD_CONCURRENCY_TRUE@concurrent = 316 quick_test = vector_test avl_test operators numericConstants \ 317 expression enum array typeof cast dtor-early-exit init_once \ 318 attributes $(am__append_1) 319 @BUILD_CONCURRENCY_FALSE@concurrent = no 320 @BUILD_CONCURRENCY_TRUE@concurrent = yes 321 @BUILD_CONCURRENCY_FALSE@concurrent_test = 322 @BUILD_CONCURRENCY_TRUE@concurrent_test = \ 323 @BUILD_CONCURRENCY_TRUE@ coroutine \ 324 @BUILD_CONCURRENCY_TRUE@ fmtLines \ 325 @BUILD_CONCURRENCY_TRUE@ pingpong \ 326 @BUILD_CONCURRENCY_TRUE@ prodcons \ 327 @BUILD_CONCURRENCY_TRUE@ thread \ 328 @BUILD_CONCURRENCY_TRUE@ matrixSum \ 329 @BUILD_CONCURRENCY_TRUE@ monitor \ 330 @BUILD_CONCURRENCY_TRUE@ multi-monitor \ 331 @BUILD_CONCURRENCY_TRUE@ boundedBuffer \ 332 @BUILD_CONCURRENCY_TRUE@ preempt \ 333 @BUILD_CONCURRENCY_TRUE@ sched-int-block \ 334 @BUILD_CONCURRENCY_TRUE@ sched-int-disjoint \ 335 @BUILD_CONCURRENCY_TRUE@ sched-int-wait \ 336 @BUILD_CONCURRENCY_TRUE@ sched-ext-barge \ 337 @BUILD_CONCURRENCY_TRUE@ sched-ext-dtor \ 338 @BUILD_CONCURRENCY_TRUE@ sched-ext-else \ 339 @BUILD_CONCURRENCY_TRUE@ sched-ext-parse \ 340 @BUILD_CONCURRENCY_TRUE@ sched-ext-recurse \ 341 @BUILD_CONCURRENCY_TRUE@ sched-ext-statment \ 342 @BUILD_CONCURRENCY_TRUE@ sched-ext-when 343 318 344 319 345 # applies to both programs 320 346 DEBUG_FLAGS = 321 347 BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ \ 322 $(am__append_ 1) $(am__append_2) $(am__append_3)323 TEST_FLAGS = $(if $(test), 2> $(test), )348 $(am__append_2) $(am__append_3) $(am__append_4) 349 TEST_FLAGS = $(if $(test), 2> .err/${@}.log, ) 324 350 AM_CFLAGS = ${TEST_FLAGS} ${BUILD_FLAGS} 325 351 fstream_test_SOURCES = fstream_test.c 326 fstream_test_CFLAGS = $(if $(test), 2>> $(test), ) ${BUILD_FLAGS}352 fstream_test_CFLAGS = $(if $(test), 2>> .err/fstream_test.log, ) ${BUILD_FLAGS} 327 353 vector_test_SOURCES = vector/vector_int.c vector/array.c vector/vector_test.c 328 vector_test_CFLAGS = $(if $(test), 2>> $(test), ) ${BUILD_FLAGS}354 vector_test_CFLAGS = $(if $(test), 2>> .err/vector_test.log, ) ${BUILD_FLAGS} 329 355 avl_test_SOURCES = avltree/avl_test.c avltree/avl0.c avltree/avl1.c avltree/avl2.c avltree/avl3.c avltree/avl4.c avltree/avl-private.c 330 avl_test_CFLAGS = $(if $(test), 2>> $(test), ) ${BUILD_FLAGS}356 avl_test_CFLAGS = $(if $(test), 2>> .err/avl_test.log, ) ${BUILD_FLAGS} 331 357 all: all-am 332 358 … … 807 833 808 834 all-local : 809 @+python test.py --debug=${debug} ${concurrent} ${quick_test}835 @+python test.py --debug=${debug} --concurrent=${concurrent} ${quick_test} 810 836 811 837 all-tests : 812 @+python test.py --all --debug=${debug} ${concurrent} # '@' => do not echo command (SILENT), '+' => allows recursive make from within python program838 @+python test.py --all --debug=${debug} --concurrent=${concurrent} # '@' => do not echo command (SILENT), '+' => allows recursive make from within python program 813 839 814 840 clean-local : … … 816 842 817 843 list : 818 @+python test.py --list ${concurrent}844 @+python test.py --list --concurrent=${concurrent} 819 845 820 846 concurrency : 821 @+python test.py --debug=${debug} ${concurrent} ${concurrent_test}847 @+python test.py --debug=${debug} --concurrent=${concurrent} ${concurrent_test} 822 848 823 849 .dummy : .dummy.c @CFA_BINDIR@/@CFA_NAME@ -
src/tests/except-mac.h
rc13e8dc8 r9c35431 7 7 8 8 // The fully (perhaps overly) qualified name of the base exception type: 9 #define BASE_EXCEPT __cfa abi_ehm__base_exception_t9 #define BASE_EXCEPT __cfaehm__base_exception_t 10 10 11 11 // Get the name of the vtable type and vtable instance for an exception type: … … 30 30 size_t size; \ 31 31 void (*copy)(except_name *this, except_name * other); \ 32 void (*free)(except_name &this); \32 void (*free)(except_name *this); \ 33 33 const char * (*msg)(except_name *this); \ 34 34 __VA_ARGS__ \ … … 42 42 // In each constructor the vtable must be initialized. 43 43 #define VTABLE_INIT(this_name,except_name) \ 44 this_name .virtual_table = &INSTANCE(except_name)44 this_name->virtual_table = &INSTANCE(except_name) 45 45 46 46 // Declare the vtable instance. This should end an exception declaration. … … 73 73 this->virtual_table = other->virtual_table; \ 74 74 } \ 75 void ?{}(name &this) { \75 void ?{}(name * this) { \ 76 76 VTABLE_INIT(this,name); \ 77 77 } \ -
src/tests/pybin/tools.py
rc13e8dc8 r9c35431 1 from __future__ import print_function2 3 1 import __main__ 4 2 import argparse 5 import multiprocessing6 3 import os 7 4 import re 8 import signal9 5 import stat 10 import sys11 6 12 from pybin import settings13 7 from subprocess import Popen, PIPE, STDOUT 14 8 15 ################################################################################16 # shell helpers17 ################################################################################18 19 9 # helper functions to run terminal commands 20 def sh(cmd, print2stdout = True, input = None): 21 # add input redirection if needed 22 if input and os.path.isfile(input): 23 cmd += " < %s" % input 24 25 # if this is a dry_run, only print the commands that would be ran 26 if settings.dry_run : 10 def sh(cmd, dry_run = False, print2stdout = True): 11 if dry_run : # if this is a dry_run, only print the commands that would be ran 27 12 print("cmd: %s" % cmd) 28 13 return 0, None 29 30 # otherwise create a pipe and run the desired command 31 else : 14 else : # otherwise create a pipe and run the desired command 32 15 proc = Popen(cmd, stdout=None if print2stdout else PIPE, stderr=STDOUT, shell=True) 33 16 out, err = proc.communicate() … … 35 18 36 19 # Remove 1 or more files silently 37 def rm( files ):20 def rm( files, dry_run = False ): 38 21 try: 39 22 for file in files: 40 sh("rm -f %s > /dev/null 2>&1" % file )23 sh("rm -f %s > /dev/null 2>&1" % file, dry_run) 41 24 except TypeError: 42 sh("rm -f %s > /dev/null 2>&1" % files )25 sh("rm -f %s > /dev/null 2>&1" % files, dry_run) 43 26 44 27 def chdir( dest = __main__.__file__ ): … … 47 30 os.chdir(dname) 48 31 32 # helper function to replace patterns in a file 33 def file_replace(fname, pat, s_after): 34 # first, see if the pattern is even in the file. 35 with open(fname) as f: 36 if not any(re.search(pat, line) for line in f): 37 return # pattern does not occur in file so we are done. 38 39 # pattern is in the file, so perform replace operation. 40 with open(fname) as f: 41 out_fname = fname + ".tmp" 42 out = open(out_fname, "w") 43 for line in f: 44 out.write(re.sub(pat, s_after, line)) 45 out.close() 46 os.rename(out_fname, fname) 47 48 # helper function to check if a files contains only a spacific string 49 def fileContainsOnly(file, text) : 50 with open(file) as f: 51 ff = f.read().strip() 52 result = ff == text.strip() 53 54 return result; 55 56 # check whether or not a file is executable 57 def fileIsExecutable(file) : 58 try : 59 fileinfo = os.stat(file) 60 return bool(fileinfo.st_mode & stat.S_IXUSR) 61 except Exception as inst: 62 print(type(inst)) # the exception instance 63 print(inst.args) # arguments stored in .args 64 print(inst) 65 return False 66 67 # check if arguments is yes or no 68 def yes_no(string): 69 if string == "yes" : 70 return True 71 if string == "no" : 72 return False 73 raise argparse.ArgumentTypeError(msg) 74 return False 75 49 76 # diff two files 50 def diff( lhs, rhs ):77 def diff( lhs, rhs, dry_run ): 51 78 # diff the output of the files 52 79 diff_cmd = ("diff --ignore-all-space " … … 67 94 68 95 # fetch return code and error from the diff command 69 return sh(diff_cmd % (lhs, rhs), False) 70 71 # call make 72 def make(target, flags = '', redirects = '', error_file = None, silent = False): 73 test_param = """test="%s" """ % (error_file) if error_file else '' 74 cmd = ' '.join([ 75 settings.make, 76 '-s' if silent else '', 77 test_param, 78 settings.debug.flags, 79 flags, 80 target, 81 redirects 82 ]) 83 return sh(cmd) 84 85 ################################################################################ 86 # file handling 87 ################################################################################ 88 89 # helper function to replace patterns in a file 90 def file_replace(fname, pat, s_after): 91 # first, see if the pattern is even in the file. 92 with open(fname) as f: 93 if not any(re.search(pat, line) for line in f): 94 return # pattern does not occur in file so we are done. 95 96 # pattern is in the file, so perform replace operation. 97 with open(fname) as f: 98 out_fname = fname + ".tmp" 99 out = open(out_fname, "w") 100 for line in f: 101 out.write(re.sub(pat, s_after, line)) 102 out.close() 103 os.rename(out_fname, fname) 104 105 # helper function to check if a files contains only a specific string 106 def fileContainsOnly(file, text) : 107 with open(file) as f: 108 ff = f.read().strip() 109 result = ff == text.strip() 110 111 return result; 112 113 # check whether or not a file is executable 114 def fileIsExecutable(file) : 115 try : 116 fileinfo = os.stat(file) 117 return bool(fileinfo.st_mode & stat.S_IXUSR) 118 except Exception as inst: 119 print(type(inst)) # the exception instance 120 print(inst.args) # arguments stored in .args 121 print(inst) 122 return False 123 124 # transform path to canonical form 125 def canonicalPath(path): 126 return os.path.join('.', os.path.normpath(path) ) 127 128 # compare path even if form is different 129 def pathCmp(lhs, rhs): 130 return canonicalPath( lhs ) == canonicalPath( rhs ) 131 132 # walk all files in a path 133 def pathWalk( op ): 134 def step(_, dirname, names): 135 for name in names: 136 path = os.path.join(dirname, name) 137 138 op( path ) 139 140 # Start the walk 141 os.path.walk('.', step, '') 142 143 ################################################################################ 144 # system 145 ################################################################################ 146 147 # parses the Makefile to find the machine type (32-bit / 64-bit) 148 def getMachineType(): 149 sh('echo "void ?{}(int&a,int b){}int main(){return 0;}" > .dummy.c') 150 ret, out = make('.dummy', silent = True) 151 152 if ret != 0: 153 print("Failed to identify architecture:") 154 print(out) 155 print("Stopping") 156 rm( (".dummy.c",".dummy") ) 157 sys.exit(1) 158 159 _, out = sh("file .dummy", print2stdout=False) 160 rm( (".dummy.c",".dummy") ) 161 162 if settings.dry_run : 163 return 'x64' 164 165 return re.search(r"[^,]+,([^,]+),", out).group(1).strip() 166 167 # count number of jobs to create 168 def jobCount( options, tests ): 169 # check if the user already passed in a number of jobs for multi-threading 170 make_flags = os.environ.get('MAKEFLAGS') 171 make_jobs_fds = re.search("--jobserver-(auth|fds)=\s*([0-9]+),([0-9]+)", make_flags) if make_flags else None 172 if make_jobs_fds : 173 tokens = os.read(int(make_jobs_fds.group(2)), 1024) 174 options.jobs = len(tokens) 175 os.write(int(make_jobs_fds.group(3)), tokens) 176 else : 177 options.jobs = multiprocessing.cpu_count() 178 179 # make sure we have a valid number of jobs that corresponds to user input 180 if options.jobs <= 0 : 181 print('ERROR: Invalid number of jobs', file=sys.stderr) 182 sys.exit(1) 183 184 return min( options.jobs, len(tests) ), True if make_flags else False 185 186 # setup a proper processor pool with correct signal handling 187 def setupPool(jobs): 188 original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) 189 pool = multiprocessing.Pool(jobs) 190 signal.signal(signal.SIGINT, original_sigint_handler) 191 192 return pool 193 194 # handle signals in scope 195 class SignalHandling(): 196 def __enter__(self): 197 # enable signal handling 198 signal.signal(signal.SIGINT, signal.SIG_DFL) 199 200 def __exit__(self, type, value, traceback): 201 # disable signal handling 202 signal.signal(signal.SIGINT, signal.SIG_IGN) 203 204 ################################################################################ 205 # misc 206 ################################################################################ 207 208 # check if arguments is yes or no 209 def yes_no(string): 210 if string == "yes" : 211 return True 212 if string == "no" : 213 return False 214 raise argparse.ArgumentTypeError(msg) 215 return False 216 217 218 settings.set_machine_default( getMachineType ) 96 return sh(diff_cmd % (lhs, rhs), dry_run, False) -
src/tests/test.py
rc13e8dc8 r9c35431 2 2 from __future__ import print_function 3 3 4 from functools import partial 5 from multiprocessing import Pool 6 from os import listdir, environ 7 from os.path import isfile, join, splitext 4 8 from pybin.tools import * 5 from pybin.test_run import *6 from pybin import settings7 9 8 10 import argparse 11 import multiprocessing 12 import os 9 13 import re 14 import signal 10 15 import sys 11 16 … … 14 19 ################################################################################ 15 20 16 def findTests(): 17 expected = [] 18 19 def matchTest(path): 20 match = re.search("(\.[\w\/\-_]*)\/.expect\/([\w\-_]+)(\.[\w\-_]+)?\.txt", path) 21 if match : 22 test = Test() 23 test.name = match.group(2) 24 test.path = match.group(1) 25 test.arch = match.group(3)[1:] if match.group(3) else None 26 if settings.arch.match(test.arch): 27 expected.append(test) 28 29 pathWalk( matchTest ) 30 31 return expected 21 # Test class that defines what a test is 22 class Test: 23 def __init__(self, name, path): 24 self.name, self.path = name, path 25 26 class TestResult: 27 SUCCESS = 0 28 FAILURE = 1 29 TIMEOUT = 124 30 31 # parses the Makefile to find the machine type (32-bit / 64-bit) 32 def getMachineType(): 33 sh('echo "void ?{}(int&a,int b){}int main(){return 0;}" > .dummy.c') 34 ret, out = sh("make .dummy -s", print2stdout=True) 35 36 if ret != 0: 37 print("Failed to identify architecture:") 38 print(out) 39 print("Stopping") 40 rm( (".dummy.c",".dummy") ) 41 sys.exit(1) 42 43 _, out = sh("file .dummy", print2stdout=False) 44 rm( (".dummy.c",".dummy") ) 45 46 return re.search("ELF\s([0-9]+)-bit", out).group(1) 47 48 def listTestsFolder(folder) : 49 path = ('./.expect/%s/' % folder) if folder else './.expect/' 50 subpath = "%s/" % folder if folder else "" 51 52 # tests directly in the .expect folder will always be processed 53 return map(lambda fname: Test(fname, subpath + fname), 54 [splitext(f)[0] for f in listdir( path ) 55 if not f.startswith('.') and f.endswith('.txt') 56 ]) 32 57 33 58 # reads the directory ./.expect and indentifies the tests 34 def listTests( includes, excludes ): 35 includes = [canonicalPath( i ) for i in includes] if includes else None 36 excludes = [canonicalPath( i ) for i in excludes] if excludes else None 59 def listTests( concurrent ): 60 machineType = getMachineType() 37 61 38 62 # tests directly in the .expect folder will always be processed 39 test_list = findTests() 40 41 # if we have a limited number of includes, filter by them 42 if includes: 43 test_list = [x for x in test_list if 44 x.path.startswith( tuple(includes) ) 45 ] 46 47 # # if we have a folders to excludes, filter by them 48 if excludes: 49 test_list = [x for x in test_list if not 50 x.path.startswith( tuple(excludes) ) 51 ] 52 53 return test_list 63 generic_list = listTestsFolder( "" ) 64 65 # tests in the machineType folder will be ran only for the corresponding compiler 66 typed_list = listTestsFolder( machineType ) 67 68 # tests in the concurrent folder will be ran only if concurrency is enabled 69 concurrent_list = listTestsFolder( "concurrent" ) if concurrent else [] 70 71 # append both lists to get 72 return generic_list + typed_list + concurrent_list; 54 73 55 74 # from the found tests, filter all the valid tests/desired tests … … 61 80 if options.regenerate_expected : 62 81 for testname in options.tests : 63 if Test.valid_name(testname): 64 found = [test for test in allTests if test.target() == testname] 65 tests.append( found[0] if len(found) == 1 else Test.from_target(testname) ) 82 if testname.endswith( (".c", ".cc", ".cpp") ): 83 print('ERROR: "%s", tests are not allowed to end with a C/C++/CFA extension, ignoring it' % testname, file=sys.stderr) 66 84 else : 67 print('ERROR: "%s", tests are not allowed to end with a C/C++/CFA extension, ignoring it' % testname, file=sys.stderr) 85 found = [test for test in allTests if test.name == testname] 86 tests.append( found[0] if len(found) == 1 else Test(testname, testname) ) 68 87 69 88 else : 70 89 # otherwise we only need to validate that all tests are present in the complete list 71 90 for testname in options.tests: 72 test = [t for t in allTests if pathCmp( t.target(), testname )]73 74 if test:91 test = [t for t in allTests if t.name == testname] 92 93 if len(test) != 0 : 75 94 tests.append( test[0] ) 76 95 else : … … 78 97 79 98 # make sure we have at least some test to run 80 if not tests:99 if len(tests) == 0 : 81 100 print('ERROR: No valid test to run', file=sys.stderr) 82 101 sys.exit(1) … … 89 108 parser = argparse.ArgumentParser(description='Script which runs cforall tests') 90 109 parser.add_argument('--debug', help='Run all tests in debug or release', type=yes_no, default='no') 91 parser.add_argument('-- arch', help='Test for specific architecture', type=str, default='')110 parser.add_argument('--concurrent', help='Run concurrent tests', type=yes_no, default='yes') 92 111 parser.add_argument('--dry-run', help='Don\'t run the tests, only output the commands', action='store_true') 93 112 parser.add_argument('--list', help='List all test available', action='store_true') … … 96 115 parser.add_argument('-j', '--jobs', help='Number of tests to run simultaneously', type=int, default='8') 97 116 parser.add_argument('--list-comp', help='List all valide arguments', action='store_true') 98 parser.add_argument('-I','--include', help='Directory of test to include, can be used multiple time, All if omitted', action='append')99 parser.add_argument('-E','--exclude', help='Directory of test to exclude, can be used multiple time, None if omitted', action='append')100 117 parser.add_argument('tests', metavar='test', type=str, nargs='*', help='a list of tests to run') 101 118 … … 106 123 all_tests = options.all 107 124 some_tests = len(options.tests) > 0 108 some_dirs = len(options.include) > 0 if options.include else 0109 125 110 126 # check that exactly one of the booleans is set to true 111 if not sum( (listing, all_tests, some_tests , some_dirs) ) > 0:112 print('ERROR: must have option \'--all\', \'--list\' , \'--include\', \'-I\'or non-empty test list', file=sys.stderr)127 if not sum( (listing, all_tests, some_tests) ) == 1 : 128 print('ERROR: must have option \'--all\', \'--list\' or non-empty test list', file=sys.stderr) 113 129 parser.print_help() 114 130 sys.exit(1) … … 116 132 return options 117 133 134 def jobCount( options ): 135 # check if the user already passed in a number of jobs for multi-threading 136 make_flags = environ.get('MAKEFLAGS') 137 make_jobs_fds = re.search("--jobserver-(auth|fds)=\s*([0-9]+),([0-9]+)", make_flags) if make_flags else None 138 if make_jobs_fds : 139 tokens = os.read(int(make_jobs_fds.group(2)), 1024) 140 options.jobs = len(tokens) 141 os.write(int(make_jobs_fds.group(3)), tokens) 142 else : 143 options.jobs = multiprocessing.cpu_count() 144 145 # make sure we have a valid number of jobs that corresponds to user input 146 if options.jobs <= 0 : 147 print('ERROR: Invalid number of jobs', file=sys.stderr) 148 sys.exit(1) 149 150 return min( options.jobs, len(tests) ), True if make_flags else False 151 118 152 ################################################################################ 119 153 # running test functions 120 154 ################################################################################ 121 155 # logic to run a single test and return the result (No handling of printing or other test framework logic) 122 def run_single_test(test ):156 def run_single_test(test, generate, dry_run, debug): 123 157 124 158 # find the output file based on the test name and options flag 125 out_file = test.target_output() 126 err_file = test.error_log() 127 cmp_file = test.expect() 128 in_file = test.input() 129 130 # prepare the proper directories 131 test.prepare() 159 out_file = (".out/%s.log" % test.name) if not generate else (".expect/%s.txt" % test.path) 160 err_file = ".err/%s.log" % test.name 132 161 133 162 # remove any outputs from the previous tests to prevent side effects 134 rm( (out_file, err_file, test.target()) ) 163 rm( (out_file, err_file, test.name), dry_run ) 164 165 options = "-debug" if debug else "-nodebug" 135 166 136 167 # build, skipping to next test on error 137 make_ret, _ = make( test.target(),138 redirects = "2> %s 1> /dev/null" % out_file, 139 error_file = err_file140 )168 make_ret, _ = sh("""%s test=yes DEBUG_FLAGS="%s" %s 2> %s 1> /dev/null""" % (make_cmd, options, test.name, out_file), dry_run) 169 170 retcode = 0 171 error = None 141 172 142 173 # if the make command succeds continue otherwise skip to diff 143 if make_ret == 0 or settings.dry_run: 144 if settings.dry_run or fileIsExecutable(test.target()) : 174 if make_ret == 0 : 175 # fetch optional input 176 stdinput = "< .in/%s.txt" % test.name if isfile(".in/%s.txt" % test.name) else "" 177 178 if fileIsExecutable(test.name) : 145 179 # run test 146 retcode, _ = sh("timeout 60 %s > %s 2>&1" % (test.target(), out_file), input = in_file)180 retcode, _ = sh("timeout 60 ./%s %s > %s 2>&1" % (test.name, stdinput, out_file), dry_run) 147 181 else : 148 182 # simply cat the result into the output 149 retcode, _ = sh("cat %s > %s" % (test.target(), out_file)) 150 else: 151 retcode, _ = sh("mv %s %s" % (err_file, out_file)) 152 183 sh("cat %s > %s" % (test.name, out_file), dry_run) 184 185 else : 186 # command failed save the log to less temporary file 187 sh("mv %s %s" % (err_file, out_file), dry_run) 153 188 154 189 if retcode == 0: 155 if settings.generating:190 if generate : 156 191 # if we are ounly generating the output we still need to check that the test actually exists 157 if not settings.dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'. Stop." % test.target()) :192 if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'. Stop." % test.name) : 158 193 retcode = 1; 159 error = "\t\tNo make target for test %s!" % test. target()194 error = "\t\tNo make target for test %s!" % test.name 160 195 sh("rm %s" % out_file, False) 161 else:162 error = None163 196 else : 164 197 # fetch return code and error from the diff command 165 retcode, error = diff( cmp_file, out_file)198 retcode, error = diff(".expect/%s.txt" % test.path, ".out/%s.log" % test.name, dry_run) 166 199 167 200 else: … … 171 204 172 205 # clean the executable 173 sh("rm -f %s > /dev/null 2>&1" % test. target())206 sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run) 174 207 175 208 return retcode, error 176 209 177 210 # run a single test and handle the errors, outputs, printing, exception handling, etc. 178 def run_test_worker(t) : 179 180 with SignalHandling(): 181 # print formated name 182 name_txt = "%20s " % t.name 183 184 retcode, error = run_single_test(t) 185 186 # update output based on current action 187 result_txt = TestResult.toString( retcode ) 188 189 #print result with error if needed 190 text = name_txt + result_txt 191 out = sys.stdout 192 if error : 193 text = text + "\n" + error 194 out = sys.stderr 195 196 print(text, file = out) 197 sys.stdout.flush() 198 sys.stderr.flush() 211 def run_test_worker(t, generate, dry_run, debug) : 212 213 signal.signal(signal.SIGINT, signal.SIG_DFL) 214 # print formated name 215 name_txt = "%20s " % t.name 216 217 retcode, error = run_single_test(t, generate, dry_run, debug) 218 219 # update output based on current action 220 if generate : 221 if retcode == TestResult.SUCCESS: result_txt = "Done" 222 elif retcode == TestResult.TIMEOUT: result_txt = "TIMEOUT" 223 else : result_txt = "ERROR code %d" % retcode 224 else : 225 if retcode == TestResult.SUCCESS: result_txt = "PASSED" 226 elif retcode == TestResult.TIMEOUT: result_txt = "TIMEOUT" 227 else : result_txt = "FAILED with code %d" % retcode 228 229 #print result with error if needed 230 text = name_txt + result_txt 231 out = sys.stdout 232 if error : 233 text = text + "\n" + error 234 out = sys.stderr 235 236 print(text, file = out) 237 sys.stdout.flush() 238 sys.stderr.flush() 239 signal.signal(signal.SIGINT, signal.SIG_IGN) 199 240 200 241 return retcode != TestResult.SUCCESS 201 242 202 243 # run the given list of tests with the given parameters 203 def run_tests(tests, jobs) :244 def run_tests(tests, generate, dry_run, jobs, debug) : 204 245 # clean the sandbox from previous commands 205 make('clean', redirects = '> /dev/null 2>&1') 246 sh("%s clean > /dev/null 2>&1" % make_cmd, dry_run) 247 248 # make sure the required folder are present 249 sh('mkdir -p .out .expect .err', dry_run) 250 251 if generate : 252 print( "Regenerate tests for: " ) 206 253 207 254 # create the executor for our jobs and handle the signal properly 208 pool = setupPool(jobs) 255 original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) 256 pool = Pool(jobs) 257 signal.signal(signal.SIGINT, original_sigint_handler) 209 258 210 259 # for each test to run 211 260 try : 212 results = pool.map_async( 213 run_test_worker, 214 tests, 215 chunksize = 1 216 ).get(7200) 261 results = pool.map_async(partial(run_test_worker, generate=generate, dry_run=dry_run, debug=debug), tests, chunksize = 1 ).get(7200) 217 262 except KeyboardInterrupt: 218 263 pool.terminate() … … 221 266 222 267 # clean the workspace 223 make('clean', redirects = '> /dev/null 2>&1')268 sh("%s clean > /dev/null 2>&1" % make_cmd, dry_run) 224 269 225 270 for failed in results: … … 240 285 options = getOptions() 241 286 242 # init global settings243 settings.init( options )244 245 287 # fetch the liest of all valid tests 246 allTests = listTests( options. include, options.exclude)288 allTests = listTests( options.concurrent ) 247 289 248 290 # if user wants all tests than no other treatement of the test list is required 249 if options.all or options.list or options.list_comp or options.include:291 if options.all or options.list or options.list_comp : 250 292 tests = allTests 251 293 252 #otherwise we need to validate that the test list that was entered is valid253 else :294 else : 295 #otherwise we need to validate that the test list that was entered is valid 254 296 tests = validTests( options ) 255 297 256 298 # sort the test alphabetically for convenience 257 tests.sort(key=lambda t: (t.arch if t.arch else '') + t.target())299 tests.sort(key=lambda t: t.name) 258 300 259 301 # users may want to simply list the tests 260 302 if options.list_comp : 261 print("-h --help --debug -- dry-run --list --arch--all --regenerate-expected -j --jobs ", end='')262 print(" ".join(map(lambda t: "%s" % (t. target()), tests)))303 print("-h --help --debug --concurrent --dry-run --list --all --regenerate-expected -j --jobs ", end='') 304 print(" ".join(map(lambda t: "%s" % (t.name), tests))) 263 305 264 306 elif options.list : 265 print("Listing for %s:%s"% (settings.arch.string, settings.debug.string)) 266 print("\n".join(map(lambda t: "%s" % (t.toString()), tests))) 267 268 else : 269 options.jobs, forceJobs = jobCount( options, tests ) 270 settings.updateMakeCmd(forceJobs, options.jobs) 271 272 print('%s (%s:%s) on %i cores' % ( 273 'Regenerate tests' if settings.generating else 'Running', 274 settings.arch.string, 275 settings.debug.string, 276 options.jobs 277 )) 307 print("\n".join(map(lambda t: "%s (%s)" % (t.name, t.path), tests))) 308 309 else : 310 options.jobs, forceJobs = jobCount( options ) 311 312 print('Running (%s) on %i cores' % ("debug" if options.debug else "no debug", options.jobs)) 313 make_cmd = "make" if forceJobs else ("make -j%i" % options.jobs) 278 314 279 315 # otherwise run all tests and make sure to return the correct error code 280 sys.exit( run_tests(tests, options. jobs) )316 sys.exit( run_tests(tests, options.regenerate_expected, options.dry_run, options.jobs, options.debug) )
Note:
See TracChangeset
for help on using the changeset viewer.