Changeset 5ebb2fbc


Ignore:
Timestamp:
Jan 18, 2017, 12:47:15 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e9e4e9ee
Parents:
f3b0a07 (diff), c49bf54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Files:
8 added
20 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/FixNames.cc

    rf3b0a07 r5ebb2fbc  
    2222#include "SymTab/Mangler.h"
    2323#include "OperatorTable.h"
    24 
    25 extern std::unique_ptr<FunctionDecl> translation_unit_main_signature;
     24#include "FixMain.h"
    2625
    2726namespace CodeGen {
     
    119118
    120119                if(is_main( SymTab::Mangler::mangle(functionDecl, true, true) )) {
    121                         if(translation_unit_main_signature) {
    122                                 throw SemanticError("Multiple definition of main routine\n", functionDecl);
     120                        int nargs = functionDecl->get_functionType()->get_parameters().size();
     121                        if( !(nargs == 0 || nargs == 2 || nargs == 3) ) {
     122                                throw SemanticError("Main expected to have 0, 2 or 3 arguments\n", functionDecl);
    123123                        }
    124 
    125124                        functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), "0") ) ) );
    126                         translation_unit_main_signature.reset( functionDecl->clone() );
     125                        CodeGen::FixMain::registerMain( functionDecl );
    127126                }
    128127        }
  • src/CodeGen/module.mk

    rf3b0a07 r5ebb2fbc  
    66## file "LICENCE" distributed with Cforall.
    77##
    8 ## module.mk -- 
     8## module.mk --
    99##
    1010## Author           : Richard C. Bilson
     
    2222        CodeGen/GenType.cc \
    2323        CodeGen/FixNames.cc \
     24        CodeGen/FixMain.cc \
    2425        CodeGen/OperatorTable.cc
  • src/GenPoly/GenPoly.cc

    rf3b0a07 r5ebb2fbc  
    2828                        for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) {
    2929                                TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
    30                                 assert(paramType && "Aggregate parameters should be type expressions");
     30                                assertf(paramType, "Aggregate parameters should be type expressions");
    3131                                if ( isPolyType( paramType->get_type(), env ) ) return true;
    3232                        }
  • src/Makefile.in

    rf3b0a07 r5ebb2fbc  
    9797        CodeGen/driver_cfa_cpp-GenType.$(OBJEXT) \
    9898        CodeGen/driver_cfa_cpp-FixNames.$(OBJEXT) \
     99        CodeGen/driver_cfa_cpp-FixMain.$(OBJEXT) \
    99100        CodeGen/driver_cfa_cpp-OperatorTable.$(OBJEXT) \
    100101        Common/driver_cfa_cpp-SemanticError.$(OBJEXT) \
     
    374375SRC = main.cc MakeLibCfa.cc CodeGen/Generate.cc \
    375376        CodeGen/CodeGenerator.cc CodeGen/GenType.cc \
    376         CodeGen/FixNames.cc CodeGen/OperatorTable.cc \
    377         Common/SemanticError.cc Common/UniqueName.cc \
    378         Common/DebugMalloc.cc Common/Assert.cc \
     377        CodeGen/FixNames.cc CodeGen/FixMain.cc \
     378        CodeGen/OperatorTable.cc Common/SemanticError.cc \
     379        Common/UniqueName.cc Common/DebugMalloc.cc Common/Assert.cc \
    379380        ControlStruct/LabelGenerator.cc ControlStruct/LabelFixer.cc \
    380381        ControlStruct/MLEMutator.cc ControlStruct/Mutate.cc \
     
    520521        CodeGen/$(DEPDIR)/$(am__dirstamp)
    521522CodeGen/driver_cfa_cpp-FixNames.$(OBJEXT): CodeGen/$(am__dirstamp) \
     523        CodeGen/$(DEPDIR)/$(am__dirstamp)
     524CodeGen/driver_cfa_cpp-FixMain.$(OBJEXT): CodeGen/$(am__dirstamp) \
    522525        CodeGen/$(DEPDIR)/$(am__dirstamp)
    523526CodeGen/driver_cfa_cpp-OperatorTable.$(OBJEXT):  \
     
    805808        -rm -f *.$(OBJEXT)
    806809        -rm -f CodeGen/driver_cfa_cpp-CodeGenerator.$(OBJEXT)
     810        -rm -f CodeGen/driver_cfa_cpp-FixMain.$(OBJEXT)
    807811        -rm -f CodeGen/driver_cfa_cpp-FixNames.$(OBJEXT)
    808812        -rm -f CodeGen/driver_cfa_cpp-GenType.$(OBJEXT)
     
    913917@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/driver_cfa_cpp-main.Po@am__quote@
    914918@AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/driver_cfa_cpp-CodeGenerator.Po@am__quote@
     919@AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/driver_cfa_cpp-FixMain.Po@am__quote@
    915920@AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/driver_cfa_cpp-FixNames.Po@am__quote@
    916921@AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/driver_cfa_cpp-GenType.Po@am__quote@
     
    11151120@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeGen/driver_cfa_cpp-FixNames.obj `if test -f 'CodeGen/FixNames.cc'; then $(CYGPATH_W) 'CodeGen/FixNames.cc'; else $(CYGPATH_W) '$(srcdir)/CodeGen/FixNames.cc'; fi`
    11161121
     1122CodeGen/driver_cfa_cpp-FixMain.o: CodeGen/FixMain.cc
     1123@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT CodeGen/driver_cfa_cpp-FixMain.o -MD -MP -MF CodeGen/$(DEPDIR)/driver_cfa_cpp-FixMain.Tpo -c -o CodeGen/driver_cfa_cpp-FixMain.o `test -f 'CodeGen/FixMain.cc' || echo '$(srcdir)/'`CodeGen/FixMain.cc
     1124@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) CodeGen/$(DEPDIR)/driver_cfa_cpp-FixMain.Tpo CodeGen/$(DEPDIR)/driver_cfa_cpp-FixMain.Po
     1125@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='CodeGen/FixMain.cc' object='CodeGen/driver_cfa_cpp-FixMain.o' libtool=no @AMDEPBACKSLASH@
     1126@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1127@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeGen/driver_cfa_cpp-FixMain.o `test -f 'CodeGen/FixMain.cc' || echo '$(srcdir)/'`CodeGen/FixMain.cc
     1128
     1129CodeGen/driver_cfa_cpp-FixMain.obj: CodeGen/FixMain.cc
     1130@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT CodeGen/driver_cfa_cpp-FixMain.obj -MD -MP -MF CodeGen/$(DEPDIR)/driver_cfa_cpp-FixMain.Tpo -c -o CodeGen/driver_cfa_cpp-FixMain.obj `if test -f 'CodeGen/FixMain.cc'; then $(CYGPATH_W) 'CodeGen/FixMain.cc'; else $(CYGPATH_W) '$(srcdir)/CodeGen/FixMain.cc'; fi`
     1131@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) CodeGen/$(DEPDIR)/driver_cfa_cpp-FixMain.Tpo CodeGen/$(DEPDIR)/driver_cfa_cpp-FixMain.Po
     1132@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='CodeGen/FixMain.cc' object='CodeGen/driver_cfa_cpp-FixMain.obj' libtool=no @AMDEPBACKSLASH@
     1133@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1134@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeGen/driver_cfa_cpp-FixMain.obj `if test -f 'CodeGen/FixMain.cc'; then $(CYGPATH_W) 'CodeGen/FixMain.cc'; else $(CYGPATH_W) '$(srcdir)/CodeGen/FixMain.cc'; fi`
     1135
    11171136CodeGen/driver_cfa_cpp-OperatorTable.o: CodeGen/OperatorTable.cc
    11181137@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT CodeGen/driver_cfa_cpp-OperatorTable.o -MD -MP -MF CodeGen/$(DEPDIR)/driver_cfa_cpp-OperatorTable.Tpo -c -o CodeGen/driver_cfa_cpp-OperatorTable.o `test -f 'CodeGen/OperatorTable.cc' || echo '$(srcdir)/'`CodeGen/OperatorTable.cc
  • src/SynTree/FunctionDecl.cc

    rf3b0a07 r5ebb2fbc  
    2222#include "Common/utility.h"
    2323#include "InitTweak/InitTweak.h"
     24#include "CodeGen/FixMain.h"
    2425
    2526extern bool translation_unit_nomain;
     
    3233        // because we want to replace the main even if it is inside an extern
    3334        if ( name == "main" ) {
    34                 set_linkage( translation_unit_nomain ? LinkageSpec::C : LinkageSpec::Cforall );
     35                set_linkage( CodeGen::FixMain::mainLinkage() );
    3536        } // if
    3637}
  • src/libcfa/Makefile.am

    rf3b0a07 r5ebb2fbc  
    4040CC = ${abs_top_srcdir}/src/driver/cfa
    4141
    42 headers = limits stdlib math iostream fstream iterator rational assert containers/vector concurrency/threads
     42headers = limits stdlib math iostream fstream iterator rational assert containers/vector concurrency/coroutines concurrency/threads concurrency/kernel
    4343runtimehdrs = concurrency
    4444libobjs = ${headers:=.o}
  • src/libcfa/Makefile.in

    rf3b0a07 r5ebb2fbc  
    9898        libcfa_d_a-assert.$(OBJEXT) \
    9999        containers/libcfa_d_a-vector.$(OBJEXT) \
    100         concurrency/libcfa_d_a-threads.$(OBJEXT)
     100        concurrency/libcfa_d_a-coroutines.$(OBJEXT) \
     101        concurrency/libcfa_d_a-threads.$(OBJEXT) \
     102        concurrency/libcfa_d_a-kernel.$(OBJEXT)
    101103am__objects_2 = libcfa_d_a-libcfa-prelude.$(OBJEXT) $(am__objects_1) \
    102104        concurrency/CtxSwitch-@MACHINE_TYPE@.$(OBJEXT) \
     
    111113        libcfa_a-rational.$(OBJEXT) libcfa_a-assert.$(OBJEXT) \
    112114        containers/libcfa_a-vector.$(OBJEXT) \
    113         concurrency/libcfa_a-threads.$(OBJEXT)
     115        concurrency/libcfa_a-coroutines.$(OBJEXT) \
     116        concurrency/libcfa_a-threads.$(OBJEXT) \
     117        concurrency/libcfa_a-kernel.$(OBJEXT)
    114118am__objects_4 = libcfa_a-libcfa-prelude.$(OBJEXT) $(am__objects_3) \
    115119        concurrency/CtxSwitch-@MACHINE_TYPE@.$(OBJEXT) \
     
    272276EXTRA_FLAGS = -g -Wall -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@
    273277AM_CCASFLAGS = @CFA_FLAGS@
    274 headers = limits stdlib math iostream fstream iterator rational assert containers/vector concurrency/threads
     278headers = limits stdlib math iostream fstream iterator rational assert containers/vector concurrency/coroutines concurrency/threads concurrency/kernel
    275279runtimehdrs = concurrency
    276280libobjs = ${headers:=.o}
     
    362366        @$(MKDIR_P) concurrency/$(DEPDIR)
    363367        @: > concurrency/$(DEPDIR)/$(am__dirstamp)
     368concurrency/libcfa_d_a-coroutines.$(OBJEXT):  \
     369        concurrency/$(am__dirstamp) \
     370        concurrency/$(DEPDIR)/$(am__dirstamp)
    364371concurrency/libcfa_d_a-threads.$(OBJEXT): concurrency/$(am__dirstamp) \
     372        concurrency/$(DEPDIR)/$(am__dirstamp)
     373concurrency/libcfa_d_a-kernel.$(OBJEXT): concurrency/$(am__dirstamp) \
    365374        concurrency/$(DEPDIR)/$(am__dirstamp)
    366375concurrency/CtxSwitch-@MACHINE_TYPE@.$(OBJEXT):  \
     
    375384containers/libcfa_a-vector.$(OBJEXT): containers/$(am__dirstamp) \
    376385        containers/$(DEPDIR)/$(am__dirstamp)
     386concurrency/libcfa_a-coroutines.$(OBJEXT):  \
     387        concurrency/$(am__dirstamp) \
     388        concurrency/$(DEPDIR)/$(am__dirstamp)
    377389concurrency/libcfa_a-threads.$(OBJEXT): concurrency/$(am__dirstamp) \
     390        concurrency/$(DEPDIR)/$(am__dirstamp)
     391concurrency/libcfa_a-kernel.$(OBJEXT): concurrency/$(am__dirstamp) \
    378392        concurrency/$(DEPDIR)/$(am__dirstamp)
    379393concurrency/libcfa_a-invoke.$(OBJEXT): concurrency/$(am__dirstamp) \
     
    387401        -rm -f *.$(OBJEXT)
    388402        -rm -f concurrency/CtxSwitch-@MACHINE_TYPE@.$(OBJEXT)
     403        -rm -f concurrency/libcfa_a-coroutines.$(OBJEXT)
    389404        -rm -f concurrency/libcfa_a-invoke.$(OBJEXT)
     405        -rm -f concurrency/libcfa_a-kernel.$(OBJEXT)
    390406        -rm -f concurrency/libcfa_a-threads.$(OBJEXT)
     407        -rm -f concurrency/libcfa_d_a-coroutines.$(OBJEXT)
    391408        -rm -f concurrency/libcfa_d_a-invoke.$(OBJEXT)
     409        -rm -f concurrency/libcfa_d_a-kernel.$(OBJEXT)
    392410        -rm -f concurrency/libcfa_d_a-threads.$(OBJEXT)
    393411        -rm -f containers/libcfa_a-vector.$(OBJEXT)
     
    416434@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-stdlib.Po@am__quote@
    417435@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/CtxSwitch-@MACHINE_TYPE@.Po@am__quote@
     436@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_a-coroutines.Po@am__quote@
    418437@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_a-invoke.Po@am__quote@
     438@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_a-kernel.Po@am__quote@
    419439@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_a-threads.Po@am__quote@
     440@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_d_a-coroutines.Po@am__quote@
    420441@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_d_a-invoke.Po@am__quote@
     442@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_d_a-kernel.Po@am__quote@
    421443@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/libcfa_d_a-threads.Po@am__quote@
    422444@AMDEP_TRUE@@am__include@ @am__quote@containers/$(DEPDIR)/libcfa_a-vector.Po@am__quote@
     
    588610@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o containers/libcfa_d_a-vector.obj `if test -f 'containers/vector.c'; then $(CYGPATH_W) 'containers/vector.c'; else $(CYGPATH_W) '$(srcdir)/containers/vector.c'; fi`
    589611
     612concurrency/libcfa_d_a-coroutines.o: concurrency/coroutines.c
     613@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_d_a-coroutines.o -MD -MP -MF concurrency/$(DEPDIR)/libcfa_d_a-coroutines.Tpo -c -o concurrency/libcfa_d_a-coroutines.o `test -f 'concurrency/coroutines.c' || echo '$(srcdir)/'`concurrency/coroutines.c
     614@am__fastdepCC_TRUE@    $(AM_V_at)$(am__mv) concurrency/$(DEPDIR)/libcfa_d_a-coroutines.Tpo concurrency/$(DEPDIR)/libcfa_d_a-coroutines.Po
     615@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(AM_V_CC)source='concurrency/coroutines.c' object='concurrency/libcfa_d_a-coroutines.o' libtool=no @AMDEPBACKSLASH@
     616@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     617@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_d_a-coroutines.o `test -f 'concurrency/coroutines.c' || echo '$(srcdir)/'`concurrency/coroutines.c
     618
     619concurrency/libcfa_d_a-coroutines.obj: concurrency/coroutines.c
     620@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_d_a-coroutines.obj -MD -MP -MF concurrency/$(DEPDIR)/libcfa_d_a-coroutines.Tpo -c -o concurrency/libcfa_d_a-coroutines.obj `if test -f 'concurrency/coroutines.c'; then $(CYGPATH_W) 'concurrency/coroutines.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/coroutines.c'; fi`
     621@am__fastdepCC_TRUE@    $(AM_V_at)$(am__mv) concurrency/$(DEPDIR)/libcfa_d_a-coroutines.Tpo concurrency/$(DEPDIR)/libcfa_d_a-coroutines.Po
     622@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(AM_V_CC)source='concurrency/coroutines.c' object='concurrency/libcfa_d_a-coroutines.obj' libtool=no @AMDEPBACKSLASH@
     623@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     624@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_d_a-coroutines.obj `if test -f 'concurrency/coroutines.c'; then $(CYGPATH_W) 'concurrency/coroutines.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/coroutines.c'; fi`
     625
    590626concurrency/libcfa_d_a-threads.o: concurrency/threads.c
    591627@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_d_a-threads.o -MD -MP -MF concurrency/$(DEPDIR)/libcfa_d_a-threads.Tpo -c -o concurrency/libcfa_d_a-threads.o `test -f 'concurrency/threads.c' || echo '$(srcdir)/'`concurrency/threads.c
     
    602638@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_d_a-threads.obj `if test -f 'concurrency/threads.c'; then $(CYGPATH_W) 'concurrency/threads.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/threads.c'; fi`
    603639
     640concurrency/libcfa_d_a-kernel.o: concurrency/kernel.c
     641@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_d_a-kernel.o -MD -MP -MF concurrency/$(DEPDIR)/libcfa_d_a-kernel.Tpo -c -o concurrency/libcfa_d_a-kernel.o `test -f 'concurrency/kernel.c' || echo '$(srcdir)/'`concurrency/kernel.c
     642@am__fastdepCC_TRUE@    $(AM_V_at)$(am__mv) concurrency/$(DEPDIR)/libcfa_d_a-kernel.Tpo concurrency/$(DEPDIR)/libcfa_d_a-kernel.Po
     643@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(AM_V_CC)source='concurrency/kernel.c' object='concurrency/libcfa_d_a-kernel.o' libtool=no @AMDEPBACKSLASH@
     644@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     645@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_d_a-kernel.o `test -f 'concurrency/kernel.c' || echo '$(srcdir)/'`concurrency/kernel.c
     646
     647concurrency/libcfa_d_a-kernel.obj: concurrency/kernel.c
     648@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_d_a-kernel.obj -MD -MP -MF concurrency/$(DEPDIR)/libcfa_d_a-kernel.Tpo -c -o concurrency/libcfa_d_a-kernel.obj `if test -f 'concurrency/kernel.c'; then $(CYGPATH_W) 'concurrency/kernel.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/kernel.c'; fi`
     649@am__fastdepCC_TRUE@    $(AM_V_at)$(am__mv) concurrency/$(DEPDIR)/libcfa_d_a-kernel.Tpo concurrency/$(DEPDIR)/libcfa_d_a-kernel.Po
     650@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(AM_V_CC)source='concurrency/kernel.c' object='concurrency/libcfa_d_a-kernel.obj' libtool=no @AMDEPBACKSLASH@
     651@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     652@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_d_a-kernel.obj `if test -f 'concurrency/kernel.c'; then $(CYGPATH_W) 'concurrency/kernel.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/kernel.c'; fi`
     653
    604654concurrency/libcfa_d_a-invoke.obj: concurrency/invoke.c
    605655@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_d_a-invoke.obj -MD -MP -MF concurrency/$(DEPDIR)/libcfa_d_a-invoke.Tpo -c -o concurrency/libcfa_d_a-invoke.obj `if test -f 'concurrency/invoke.c'; then $(CYGPATH_W) 'concurrency/invoke.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/invoke.c'; fi`
     
    742792@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o containers/libcfa_a-vector.obj `if test -f 'containers/vector.c'; then $(CYGPATH_W) 'containers/vector.c'; else $(CYGPATH_W) '$(srcdir)/containers/vector.c'; fi`
    743793
     794concurrency/libcfa_a-coroutines.o: concurrency/coroutines.c
     795@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_a-coroutines.o -MD -MP -MF concurrency/$(DEPDIR)/libcfa_a-coroutines.Tpo -c -o concurrency/libcfa_a-coroutines.o `test -f 'concurrency/coroutines.c' || echo '$(srcdir)/'`concurrency/coroutines.c
     796@am__fastdepCC_TRUE@    $(AM_V_at)$(am__mv) concurrency/$(DEPDIR)/libcfa_a-coroutines.Tpo concurrency/$(DEPDIR)/libcfa_a-coroutines.Po
     797@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(AM_V_CC)source='concurrency/coroutines.c' object='concurrency/libcfa_a-coroutines.o' libtool=no @AMDEPBACKSLASH@
     798@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     799@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_a-coroutines.o `test -f 'concurrency/coroutines.c' || echo '$(srcdir)/'`concurrency/coroutines.c
     800
     801concurrency/libcfa_a-coroutines.obj: concurrency/coroutines.c
     802@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_a-coroutines.obj -MD -MP -MF concurrency/$(DEPDIR)/libcfa_a-coroutines.Tpo -c -o concurrency/libcfa_a-coroutines.obj `if test -f 'concurrency/coroutines.c'; then $(CYGPATH_W) 'concurrency/coroutines.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/coroutines.c'; fi`
     803@am__fastdepCC_TRUE@    $(AM_V_at)$(am__mv) concurrency/$(DEPDIR)/libcfa_a-coroutines.Tpo concurrency/$(DEPDIR)/libcfa_a-coroutines.Po
     804@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(AM_V_CC)source='concurrency/coroutines.c' object='concurrency/libcfa_a-coroutines.obj' libtool=no @AMDEPBACKSLASH@
     805@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     806@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_a-coroutines.obj `if test -f 'concurrency/coroutines.c'; then $(CYGPATH_W) 'concurrency/coroutines.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/coroutines.c'; fi`
     807
    744808concurrency/libcfa_a-threads.o: concurrency/threads.c
    745809@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_a-threads.o -MD -MP -MF concurrency/$(DEPDIR)/libcfa_a-threads.Tpo -c -o concurrency/libcfa_a-threads.o `test -f 'concurrency/threads.c' || echo '$(srcdir)/'`concurrency/threads.c
     
    755819@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    756820@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_a-threads.obj `if test -f 'concurrency/threads.c'; then $(CYGPATH_W) 'concurrency/threads.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/threads.c'; fi`
     821
     822concurrency/libcfa_a-kernel.o: concurrency/kernel.c
     823@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_a-kernel.o -MD -MP -MF concurrency/$(DEPDIR)/libcfa_a-kernel.Tpo -c -o concurrency/libcfa_a-kernel.o `test -f 'concurrency/kernel.c' || echo '$(srcdir)/'`concurrency/kernel.c
     824@am__fastdepCC_TRUE@    $(AM_V_at)$(am__mv) concurrency/$(DEPDIR)/libcfa_a-kernel.Tpo concurrency/$(DEPDIR)/libcfa_a-kernel.Po
     825@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(AM_V_CC)source='concurrency/kernel.c' object='concurrency/libcfa_a-kernel.o' libtool=no @AMDEPBACKSLASH@
     826@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     827@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_a-kernel.o `test -f 'concurrency/kernel.c' || echo '$(srcdir)/'`concurrency/kernel.c
     828
     829concurrency/libcfa_a-kernel.obj: concurrency/kernel.c
     830@am__fastdepCC_TRUE@    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_a-kernel.obj -MD -MP -MF concurrency/$(DEPDIR)/libcfa_a-kernel.Tpo -c -o concurrency/libcfa_a-kernel.obj `if test -f 'concurrency/kernel.c'; then $(CYGPATH_W) 'concurrency/kernel.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/kernel.c'; fi`
     831@am__fastdepCC_TRUE@    $(AM_V_at)$(am__mv) concurrency/$(DEPDIR)/libcfa_a-kernel.Tpo concurrency/$(DEPDIR)/libcfa_a-kernel.Po
     832@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(AM_V_CC)source='concurrency/kernel.c' object='concurrency/libcfa_a-kernel.obj' libtool=no @AMDEPBACKSLASH@
     833@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     834@am__fastdepCC_FALSE@   $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_a-kernel.obj `if test -f 'concurrency/kernel.c'; then $(CYGPATH_W) 'concurrency/kernel.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/kernel.c'; fi`
    757835
    758836concurrency/libcfa_a-invoke.obj: concurrency/invoke.c
  • src/libcfa/concurrency/invoke.c

    rf3b0a07 r5ebb2fbc  
    2020      void *this
    2121) {
    22       LIB_DEBUG_PRINTF("Invoke : Received %p (main %p, get_c %p)\n", this, main, get_coroutine);
     22      LIB_DEBUG_PRINTF("Invoke Coroutine : Received %p (main %p, get_c %p)\n", this, main, get_coroutine);
    2323
    2424      struct coroutine* cor = get_coroutine( this );
     
    3131
    3232      main( this );
     33
     34      //Final suspend, should never return
     35      __suspend_no_inline__F___1();
     36      assertf(false, "Resumed dead coroutine");
     37}
     38
     39void CtxInvokeThread(
     40      void (*main)(void *),
     41      struct thread_h *(*get_thread)(void *),
     42      void *this
     43) {
     44      LIB_DEBUG_PRINTF("Invoke Thread : Received %p (main %p, get_t %p)\n", this, main, get_thread);
     45
     46      __suspend_no_inline__F___1();
     47
     48      struct coroutine* cor = &get_thread( this )->c;
     49      cor->state = Active;
     50
     51      LIB_DEBUG_PRINTF("Invoke Thread : invoking main %p (args %p)\n", main, this);
     52      main( this );
     53
     54      //Final suspend, should never return
     55      __suspend_no_inline__F___1();
     56      assertf(false, "Resumed dead thread");
    3357}
    3458
     
    4064      void (*invoke)(void *)
    4165) {
    42       LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (main %p, get_c %p) to %p\n", this, main, get_coroutine, invoke);
     66      LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (main %p) to invoke (%p) from start (%p)\n", this, main, invoke, CtxStart);
    4367
    4468      struct coStack_t* stack = &get_coroutine( this )->stack;
  • src/libcfa/concurrency/invoke.h

    rf3b0a07 r5ebb2fbc  
    3535      };
    3636
     37      struct thread_h {
     38            struct coroutine c;
     39      };
     40
    3741#endif //_INVOKE_H_
    3842#else //! defined(__CFA_INVOKE_PRIVATE__)
  • src/libcfa/concurrency/threads

    rf3b0a07 r5ebb2fbc  
    99//
    1010// Author           : Thierry Delisle
    11 // Created On       : Mon Nov 28 12:27:26 2016
     11// Created On       : Tue Jan 17 12:27:26 2016
    1212// Last Modified By : Thierry Delisle
    13 // Last Modified On : Mon Nov 28 12:27:26 2016
     13// Last Modified On : --
    1414// Update Count     : 0
    1515//
     
    1818#define THREADS_H
    1919
    20 #include "assert"       //
     20#include "assert"
    2121#include "invoke.h"
     22
     23#include "coroutines"
    2224
    2325//-----------------------------------------------------------------------------
     
    2527// Anything that implements this trait can be resumed.
    2628// Anything that is resumed is a coroutine.
    27 trait is_coroutine(dtype T) {
     29trait is_thread(dtype T /*| sized(T)*/) {
    2830      void co_main(T* this);
    29       coroutine* get_coroutine(T* this);
     31      thread_h* get_thread(T* this);
     32        /*void ?{}(T*);
     33        void ^?{}(T*);*/
    3034};
     35
     36forall(otype T | is_thread(T) )
     37static inline coroutine* get_coroutine(T* this) {
     38        return &get_thread(this)->c;
     39}
    3140
    3241//-----------------------------------------------------------------------------
    3342// Ctors and dtors
    34 void ?{}(coStack_t* this);
    35 void ?{}(coroutine* this);
    36 void ^?{}(coStack_t* this);
    37 void ^?{}(coroutine* this);
     43void ?{}(thread_h* this);
     44void ^?{}(thread_h* this);
    3845
    3946//-----------------------------------------------------------------------------
    40 // Public coroutine API
    41 static inline void suspend();
     47// thread runner
     48// Structure that actually start and stop threads
     49forall(otype T | is_thread(T) )
     50struct thread {
     51        T handle;
     52};
    4253
    43 forall(dtype T | is_coroutine(T))
    44 static inline void resume(T* cor);
     54forall(otype T | is_thread(T) )
     55void ?{}( thread(T)* this );
    4556
    46 forall(dtype T | is_coroutine(T))
    47 void prime(T* cor);
     57forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } )
     58void ?{}( thread(T)* this, P params );
     59
     60forall(otype T | is_thread(T) )
     61void ^?{}( thread(T)* this );
    4862
    4963//-----------------------------------------------------------------------------
    5064// PRIVATE exposed because of inline
    51 
    52 // Start coroutine routines
    53 extern "C" {
    54       forall(dtype T | is_coroutine(T))
    55       void CtxInvokeCoroutine(T* this);
    56 
    57       forall(dtype T | is_coroutine(T))
    58       void CtxStart(T* this, void (*invoke)(T*));
    59 }
    60 
    61 // Get current coroutine
    62 extern coroutine* current_coroutine; //PRIVATE, never use directly
    63 static inline coroutine* this_coroutine(void) {
    64         return current_coroutine;
    65 }
    66 
    67 // Private wrappers for context switch and stack creation
    68 extern void corCxtSw(coroutine* src, coroutine* dst);
    69 extern void create_stack( coStack_t* this, unsigned int storageSize );
    70 
    71 // Suspend implementation inlined for performance
    72 static inline void suspend() {
    73       coroutine* src = this_coroutine();                // optimization
    74 
    75         assertf( src->last != 0,
    76                 "Attempt to suspend coroutine %.256s (%p) that has never been resumed.\n"
    77                 "Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.",
    78                 src->name, src );
    79         assertf( src->last->notHalted,
    80                 "Attempt by coroutine %.256s (%p) to suspend back to terminated coroutine %.256s (%p).\n"
    81                 "Possible cause is terminated coroutine's main routine has already returned.",
    82                 src->name, src, src->last->name, src->last );
    83 
    84         corCxtSw( src, src->last );
    85 }
    86 
    87 // Resume implementation inlined for performance
    88 forall(dtype T | is_coroutine(T))
    89 static inline void resume(T* cor) {
    90         coroutine* src = this_coroutine();              // optimization
    91         coroutine* dst = get_coroutine(cor);
    92 
    93       if( unlikely(!dst->stack.base) ) {
    94                 create_stack(&dst->stack, dst->stack.size);
    95                 CtxStart(cor, CtxInvokeCoroutine);
    96         }
    97 
    98       // not resuming self ?
    99         if ( src != dst ) {
    100                 assertf( dst->notHalted ,
    101                         "Attempt by coroutine %.256s (%p) to resume terminated coroutine %.256s (%p).\n"
    102                         "Possible cause is terminated coroutine's main routine has already returned.",
    103                         src->name, src, dst->name, dst );
    104 
    105             // set last resumer
    106                 dst->last = src;
    107         } // if
    108 
    109       // always done for performance testing
    110         corCxtSw( src, dst );
    111 }
    11265
    11366#endif //THREADS_H
  • src/libcfa/concurrency/threads.c

    rf3b0a07 r5ebb2fbc  
     1//                              -*- Mode: CFA -*-
    12//
    23// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     
    89//
    910// Author           : Thierry Delisle
    10 // Created On       : Mon Nov 28 12:27:26 2016
     11// Created On       : Tue Jan 17 12:27:26 2016
    1112// Last Modified By : Thierry Delisle
    12 // Last Modified On : Mon Nov 28 12:27:26 2016
     13// Last Modified On : --
    1314// Update Count     : 0
    1415//
    1516
    16 extern "C" {
    17 #include <stddef.h>
    18 #include <malloc.h>
    19 #include <errno.h>
    20 #include <string.h>
    21 #include <unistd.h>
    22 #include <sys/mman.h>
    23 }
     17#include "threads"
    2418
    25 #include "threads"
     19#include "kernel"
    2620#include "libhdr.h"
    2721
     
    2923#include "invoke.h"
    3024
    31 //-----------------------------------------------------------------------------
    32 // Global state variables
    33 
    34 // minimum feasible stack size in bytes
    35 #define MinStackSize 1000
    36 static size_t pageSize = 0;                             // architecture pagesize HACK, should go in proper runtime singleton
    37 
    38 //Extra private desctructor for the main
    39 //FIXME the main should not actually allocate a stack
    40 //Since the main is never resumed the extra stack does not cause
    41 //any problem but it is wasted memory
    42 void ?{}(coStack_t* this, size_t size);
    43 void ?{}(coroutine* this, size_t size);
    44 
    45 //Main coroutine
    46 //FIXME do not construct a stack for the main
    47 coroutine main_coroutine = { 1000 };
    48 
    49 //Current coroutine
    50 //Will need to be in TLS when multi-threading is added
    51 coroutine* current_coroutine = &main_coroutine;
     25#include <stdlib>
    5226
    5327//-----------------------------------------------------------------------------
    54 // Coroutine ctors and dtors
    55 void ?{}(coStack_t* this) {
    56         this->size              = 10240;        // size of stack
    57         this->storage   = NULL; // pointer to stack
    58         this->limit             = NULL; // stack grows towards stack limit
    59         this->base              = NULL; // base of stack
    60         this->context   = NULL; // address of cfa_context_t
    61         this->top               = NULL; // address of top of storage
    62         this->userStack = false;       
     28// Forward declarations
     29forall(otype T | is_thread(T) )
     30void start( thread(T)* this );
     31
     32forall(otype T | is_thread(T) )
     33void stop( thread(T)* this );
     34
     35//-----------------------------------------------------------------------------
     36// Thread ctors and dtors
     37
     38void ?{}(thread_h* this) {
     39        (&this->c){};
    6340}
    6441
    65 void ?{}(coStack_t* this, size_t size) {
    66         this{};
    67         this->size = size;
    68 
    69         create_stack(this, this->size);
     42void ^?{}(thread_h* this) {
     43        ^(&this->c){};
    7044}
    7145
    72 void ?{}(coroutine* this) {
    73         this->name = "Anonymous Coroutine";
    74         this->errno_ = 0;
    75         this->state = Start;
    76       this->notHalted = true;
    77         this->starter = NULL;
    78         this->last = NULL;
     46forall(otype T | is_thread(T) )
     47void ?{}( thread(T)* this ) {
     48        printf("thread() ctor\n");
     49        (&this->handle){};
     50        start(this);
    7951}
    8052
    81 void ?{}(coroutine* this, size_t size) {
    82         this{};
    83         (&this->stack){size};
     53forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } )
     54void ?{}( thread(T)* this, P params ) {
     55        (&this->handle){ params };
     56        start(this);
    8457}
    8558
    86 void ^?{}(coStack_t* this) {
    87         if ( ! this->userStack ) {
    88                 LIB_DEBUG_DO(
    89                         if ( mprotect( this->storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) {
    90                                 abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", this, errno, strerror( errno ) );
    91                         }
    92                 );
    93                 free( this->storage );
    94         }
     59forall(otype T | is_thread(T) )
     60void ^?{}( thread(T)* this ) {
     61        stop(this);
     62        ^(&this->handle){};
    9563}
    9664
    97 void ^?{}(coroutine* this) {}
    98 
    99 // Part of the Public API
    100 // Not inline since only ever called once per coroutine
    101 forall(dtype T | is_coroutine(T))
    102 void prime(T* cor) {
    103         coroutine* this = get_coroutine(cor);
    104         assert(this->state == Start);
    105 
    106         this->state = Primed;
    107         resume(cor);
     65//-----------------------------------------------------------------------------
     66// Starting and stopping threads
     67extern "C" {
     68      forall(dtype T | is_thread(T))
     69      void CtxInvokeThread(T * this);
    10870}
    10971
    110 // We need to call suspend from invoke.c, so we expose this wrapper that
    111 // is not inline (We can't inline Cforall in C)
    112 void suspend_no_inline(void) {
    113         suspend();
     72forall(otype T | is_thread(T))
     73void start( thread(T)* this ) {
     74        T* handle  = &this->handle;
     75        coroutine* thrd_c = get_coroutine(handle);
     76        thread_h*  thrd_h = get_thread   (handle);
     77        thrd_c->last = this_coroutine();
     78        current_coroutine = thrd_c;
     79
     80        LIB_DEBUG_PRINTF("Thread start : %p (t %p, c %p)\n", handle, thrd_c, thrd_h);
     81
     82        create_stack(&thrd_c->stack, thrd_c->stack.size);
     83        CtxStart(handle, CtxInvokeThread);
     84        CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
     85
     86        the_thread = thrd_h;
    11487}
    11588
    116 void corCxtSw(coroutine* src, coroutine* dst) {
    117         // THREAD_GETMEM( This )->disableInterrupts();
     89forall(otype T | is_thread(T) )
     90void stop( thread(T)* this ) {
    11891
    119         // set state of current coroutine to inactive
    120         src->state = Inactive;
    121 
    122         // set new coroutine that task is executing
    123         current_coroutine = dst;                       
    124 
    125         // context switch to specified coroutine
    126         CtxSwitch( src->stack.context, dst->stack.context );
    127         // when CtxSwitch returns we are back in the src coroutine             
    128 
    129         // set state of new coroutine to active
    130         src->state = Active;
    131 
    132         // THREAD_GETMEM( This )->enableInterrupts();
    133 } //ctxSwitchDirect
    134 
    135 void create_stack( coStack_t* this, unsigned int storageSize ) {
    136         //TEMP HACK do this on proper kernel startup
    137         if(pageSize == 0ul) pageSize = sysconf( _SC_PAGESIZE );
    138 
    139         size_t cxtSize = libCeiling( sizeof(machine_context_t), 8 ); // minimum alignment
    140 
    141         if ( (intptr_t)this->storage == 0 ) {
    142                 this->userStack = false;
    143                 this->size = libCeiling( storageSize, 16 );
    144                 // use malloc/memalign because "new" raises an exception for out-of-memory
    145                
    146                 // assume malloc has 8 byte alignment so add 8 to allow rounding up to 16 byte alignment
    147                 LIB_DEBUG_DO( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) );
    148                 LIB_NO_DEBUG_DO( this->storage = malloc( cxtSize + this->size + 8 ) );
    149 
    150                 LIB_DEBUG_DO(
    151                         if ( mprotect( this->storage, pageSize, PROT_NONE ) == -1 ) {
    152                                 abortf( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) );
    153                         } // if
    154                 );
    155 
    156                 if ( (intptr_t)this->storage == 0 ) {
    157                         abortf( "Attempt to allocate %d bytes of storage for coroutine or task execution-state but insufficient memory available.", this->size );
    158                 } // if
    159 
    160                 LIB_DEBUG_DO( this->limit = (char *)this->storage + pageSize );
    161                 LIB_NO_DEBUG_DO( this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ) ); // minimum alignment
    162 
    163         } else {
    164                 assertf( ((size_t)this->storage & (libAlign() - 1)) != 0ul, "Stack storage %p for task/coroutine must be aligned on %d byte boundary.", this->storage, (int)libAlign() );
    165                 this->userStack = true;
    166                 this->size = storageSize - cxtSize;
    167 
    168                 if ( this->size % 16 != 0u ) this->size -= 8;
    169 
    170                 this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ); // minimum alignment
    171         } // if
    172         assertf( this->size >= MinStackSize, "Stack size %d provides less than minimum of %d bytes for a stack.", this->size, MinStackSize );
    173 
    174         this->base = (char *)this->limit + this->size;
    175         this->context = this->base;
    176         this->top = (char *)this->context + cxtSize;
    17792}
    17893
  • src/main.cc

    rf3b0a07 r5ebb2fbc  
    1414//
    1515
    16 #include <memory>
    1716#include <iostream>
    1817#include <fstream>
     
    3534#include "CodeGen/Generate.h"
    3635#include "CodeGen/FixNames.h"
     36#include "CodeGen/FixMain.h"
    3737#include "ControlStruct/Mutate.h"
    3838#include "SymTab/Validate.h"
     
    8080static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
    8181
    82 bool translation_unit_nomain = true;
    83 std::unique_ptr<FunctionDecl> translation_unit_main_signature = nullptr;
    84 
    8582static void backtrace( int start ) {                                    // skip first N stack frames
    8683        enum { Frames = 50 };
     
    159156
    160157        parse_cmdline( argc, argv, filename );                          // process command-line arguments
    161         translation_unit_nomain = nomainp;
     158        CodeGen::FixMain::setReplaceMain( !nomainp );
    162159
    163160        try {
     
    178175                } // if
    179176
    180                 if ( optind < argc ) {                                                  // any commands after the flags and input file ? => output file name
    181                         output = new ofstream( argv[ optind ] );
    182                 } // if
    183 
    184177                // read in the builtins, extras, and the prelude
    185178                if ( ! nopreludep ) {                                                   // include gcc builtins
     
    304297                } // if
    305298
     299                if ( optind < argc ) {                                                  // any commands after the flags and input file ? => output file name
     300                        output = new ofstream( argv[ optind ] );
     301                } // if
     302
    306303                CodeGen::generate( translationUnit, *output, ! noprotop );
    307304
    308                 if( translation_unit_main_signature ) {
    309                         *output << "int main(int argc, char** argv) { return ";
    310 
    311                         *output << translation_unit_main_signature->get_scopedMangleName() << "(";
    312                         if(translation_unit_main_signature->get_functionType()->get_parameters().size() != 0){
    313                                 *output << "argc, argv";
    314                         }
    315                         *output << ");";
    316 
    317                         *output << " }\n";
    318                 }
     305                CodeGen::FixMain::fix( *output, treep ? "../prelude/bootloader.c" : CFA_LIBDIR "/bootloader.c" );
    319306
    320307                if ( output != &cout ) {
  • src/prelude/Makefile.am

    rf3b0a07 r5ebb2fbc  
    4545        ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -l prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    4646
    47 bootloader.c : bootloader.cf extras.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
     47bootloader.c : bootloader.cf prelude.cf extras.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
    4848        ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -tpm bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
    4949
  • src/prelude/Makefile.in

    rf3b0a07 r5ebb2fbc  
    441441        ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -l prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    442442
    443 bootloader.c : bootloader.cf extras.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
     443bootloader.c : bootloader.cf prelude.cf extras.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
    444444        ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -tpm bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
    445445
  • src/prelude/bootloader.cf

    rf3b0a07 r5ebb2fbc  
    1 extern int invoke_main(int argc, char* argv[], char* envp[]);
     1extern "C" { static inline int invoke_main(int argc, char* argv[], char* envp[]); }
    22
    33int main(int argc, char* argv[], char* envp[]) {
  • src/tests/.expect/32/declarationSpecifier.txt

    rf3b0a07 r5ebb2fbc  
    628628    return ((int )___retval_main__i_1);
    629629}
    630 int main(int argc, char** argv) { return __main__Fi_iPPCc__1(argc, argv); }
    631 
     630static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return __main__Fi_iPPCc__1(argc, argv); }
     631extern void *malloc(unsigned int __size);
     632extern void free(void *__ptr);
     633extern void abort(void);
     634extern int atexit(void (*__func)(void));
     635extern void exit(int __status);
     636extern int printf(const char *__restrict __format, ...);
     637static inline int invoke_main(int argc, char **argv, char **envp);
     638int main(int __argc__i_1, char **__argv__PPc_1, char **__envp__PPc_1){
     639    int ___retval_main__i_1;
     640    int _tmp_cp_ret0;
     641    ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */);
     642    ((void)(_tmp_cp_ret0) /* ^?{} */);
     643    return ((int )___retval_main__i_1);
     644}
  • src/tests/.expect/32/gccExtensions.txt

    rf3b0a07 r5ebb2fbc  
    165165    return ((int )___retval_main__i_1);
    166166}
    167 int main(int argc, char** argv) { return __main__Fi_iPPCc__1(argc, argv); }
     167static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return __main__Fi_iPPCc__1(argc, argv); }
     168extern void *malloc(unsigned int __size);
     169extern void free(void *__ptr);
     170extern void abort(void);
     171extern int atexit(void (*__func)(void));
     172extern void exit(int __status);
     173extern int printf(const char *__restrict __format, ...);
     174static inline int invoke_main(int argc, char **argv, char **envp);
     175int main(int __argc__i_1, char **__argv__PPc_1, char **__envp__PPc_1){
     176    int ___retval_main__i_1;
     177    int _tmp_cp_ret0;
     178    ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */);
     179    ((void)(_tmp_cp_ret0) /* ^?{} */);
     180    return ((int )___retval_main__i_1);
     181}
  • src/tests/.expect/64/declarationSpecifier.txt

    rf3b0a07 r5ebb2fbc  
    628628    return ((int )___retval_main__i_1);
    629629}
    630 int main(int argc, char** argv) { return __main__Fi_iPPCc__1(argc, argv); }
     630static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return __main__Fi_iPPCc__1(argc, argv); }
     631extern void *malloc(long unsigned int __size);
     632extern void free(void *__ptr);
     633extern void abort(void);
     634extern int atexit(void (*__func)(void));
     635extern void exit(int __status);
     636extern int printf(const char *__restrict __format, ...);
     637static inline int invoke_main(int argc, char **argv, char **envp);
     638int main(int __argc__i_1, char **__argv__PPc_1, char **__envp__PPc_1){
     639    int ___retval_main__i_1;
     640    int _tmp_cp_ret0;
     641    ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */);
     642    ((void)(_tmp_cp_ret0) /* ^?{} */);
     643    return ((int )___retval_main__i_1);
     644}
  • src/tests/.expect/64/gccExtensions.txt

    rf3b0a07 r5ebb2fbc  
    165165    return ((int )___retval_main__i_1);
    166166}
    167 int main(int argc, char** argv) { return __main__Fi_iPPCc__1(argc, argv); }
     167static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return __main__Fi_iPPCc__1(argc, argv); }
     168extern void *malloc(long unsigned int __size);
     169extern void free(void *__ptr);
     170extern void abort(void);
     171extern int atexit(void (*__func)(void));
     172extern void exit(int __status);
     173extern int printf(const char *__restrict __format, ...);
     174static inline int invoke_main(int argc, char **argv, char **envp);
     175int main(int __argc__i_1, char **__argv__PPc_1, char **__envp__PPc_1){
     176    int ___retval_main__i_1;
     177    int _tmp_cp_ret0;
     178    ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */);
     179    ((void)(_tmp_cp_ret0) /* ^?{} */);
     180    return ((int )___retval_main__i_1);
     181}
  • src/tests/coroutine.c

    rf3b0a07 r5ebb2fbc  
    11#include <fstream>
    2 #include <threads>
     2#include <coroutines>
    33
    44struct Fibonacci {
Note: See TracChangeset for help on using the changeset viewer.