Changeset bd06384 for src


Ignore:
Timestamp:
Mar 22, 2018, 4:49:53 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
dbc2c2c
Parents:
7e4b44db
Message:

Add static roots to GC; fix some static GC_Objects

Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r7e4b44db rbd06384  
    11061106unsigned Indenter::tabsize = 2;
    11071107
    1108 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) {
    1109         if ( node ) {
    1110                 node->print( out );
    1111         } else {
    1112                 out << "nullptr";
    1113         }
    1114         return out;
    1115 }
    1116 
    11171108// Local Variables: //
    11181109// tab-width: 4 //
  • src/Common/GC.cc

    r7e4b44db rbd06384  
    1616#include "GC.h"
    1717
     18#include "Common/PassVisitor.h"
     19
     20#include "SynTree/GcTracer.h"
     21
    1822#include <algorithm>
    1923#include <cassert>
     
    2428}
    2529
    26 GC::GC() : mark(false), old(), young(), using_young(false) {
     30GC::GC() : mark(false), using_young(false), old(), young(), static_roots() {
    2731        old.reserve(70000);
    2832}
     
    5559}
    5660
     61void GC::register_static_root(BaseSyntaxNode* root) {
     62        static_roots.push_back(root);
     63}
     64
    5765void GC::new_generation() {
    5866        using_young = true;
     67}
     68
     69void GC::trace_static_roots() {
     70        PassVisitor<GcTracer> tracer{ *this };
     71        for ( BaseSyntaxNode* root : static_roots ) {
     72                root->accept( tracer );
     73        }
    5974}
    6075
  • src/Common/GC.h

    r7e4b44db rbd06384  
    2020class GC_Traceable;
    2121class GC_Object;
     22class BaseSyntaxNode;
    2223
    2324/// Manually traced and called garbage collector
     
    3435        void register_object(GC_Object*);
    3536
     37        /// Adds an object to the set of static roots
     38        void register_static_root(BaseSyntaxNode*);
     39
    3640        /// Use young generation for subsequent new objects
    3741        void new_generation();
     42
     43        /// Traces all static roots
     44        void trace_static_roots();
    3845
    3946        /// Collects the young generation, placing survivors in old generation.
     
    5057        GC();
    5158
    52         /// The current collection's mark bit
    53         bool mark;
     59        bool mark;                 ///< The current collection's mark bit
     60        bool using_young;          ///< Is the young generation in use?
    5461
    55         typedef std::vector<class GC_Object*> Generation;
    56         Generation old;
    57         Generation young;
    58         bool using_young;
     62        using Generation = std::vector<GC_Object*>;
     63        Generation old;            ///< Old generation
     64        Generation young;          ///< Young generation
     65
     66        using StaticRoots = std::vector<BaseSyntaxNode*>;
     67        StaticRoots static_roots;  ///< Set of static-lifetime roots
    5968};
    6069
     
    8089        GC& gc = GC::get();
    8190        traceAll(gc, roots...);
     91        gc.trace_static_roots();
    8292        gc.collect_young();
    8393}
     
    8898        GC& gc = GC::get();
    8999        traceAll(gc, roots...);
     100        gc.trace_static_roots();
    90101        gc.collect();
     102}
     103
     104/// Makes a new expression as a static root
     105template<typename T, typename... Args>
     106inline T* new_static_root( Args&&... args ) {
     107        T* root = new T( std::forward<Args>(args)... );
     108        GC::get().register_static_root( root );
     109        return root;
    91110}
    92111
  • src/Common/PassVisitor.impl.h

    r7e4b44db rbd06384  
    3838        MUTATE_END( type, node );      \
    3939
    40 
     40#include "Common/GC.h"
    4141
    4242template<typename T>
     
    397397                        auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    398398                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    399                         static ObjectDecl func(
     399                        static ObjectDecl* func = new_static_root<ObjectDecl>(
    400400                                "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    401401                                new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    402402                                nullptr
    403403                        );
    404                         indexerAddId( &func );
     404                        indexerAddId( func );
    405405                        maybeAccept_impl( node->type, *this );
    406406                        maybeAccept_impl( node->statements, *this );
     
    427427                        auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    428428                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    429                         static ObjectDecl func(
     429                        static ObjectDecl* func = new_static_root<ObjectDecl>(
    430430                                "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    431431                                new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    432432                                nullptr
    433433                        );
    434                         indexerAddId( &func );
     434                        indexerAddId( func );
    435435                        maybeMutate_impl( node->type, *this );
    436436                        maybeMutate_impl( node->statements, *this );
  • src/Concurrency/Keywords.cc

    r7e4b44db rbd06384  
    1919#include <string>                  // for string, operator==
    2020
     21#include "Common/GC.h"             // for new_static_root
    2122#include "Common/PassVisitor.h"    // for PassVisitor
    2223#include "Common/SemanticError.h"  // for SemanticError
     
    203204        };
    204205
    205         Type* MutexKeyword::generic_func = new FunctionType{ noQualifiers, true };
     206        Type* MutexKeyword::generic_func = new_static_root<FunctionType>( noQualifiers, true );
    206207
    207208        //-----------------------------------------------------------------------------
  • src/Makefile.in

    r7e4b44db rbd06384  
    250250        SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT) \
    251251        SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) \
     252        SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT) \
    252253        SynTree/driver_cfa_cpp-VarExprReplacer.$(OBJEXT) \
    253254        Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT) \
     
    527528        SynTree/NamedTypeDecl.cc SynTree/TypeDecl.cc \
    528529        SynTree/Initializer.cc SynTree/TypeSubstitution.cc \
    529         SynTree/Attribute.cc SynTree/VarExprReplacer.cc \
    530         Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \
    531         Tuples/Explode.cc Virtual/ExpandCasts.cc
     530        SynTree/Attribute.cc SynTree/BaseSyntaxNode.cc \
     531        SynTree/VarExprReplacer.cc Tuples/TupleAssignment.cc \
     532        Tuples/TupleExpansion.cc Tuples/Explode.cc \
     533        Virtual/ExpandCasts.cc
    532534MAINTAINERCLEANFILES = Parser/parser.output ${libdir}/${notdir \
    533535        ${cfa_cpplib_PROGRAMS}}
     
    915917SynTree/driver_cfa_cpp-Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \
    916918        SynTree/$(DEPDIR)/$(am__dirstamp)
     919SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT):  \
     920        SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp)
    917921SynTree/driver_cfa_cpp-VarExprReplacer.$(OBJEXT):  \
    918922        SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp)
     
    10391043@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AttrType.Po@am__quote@
    10401044@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po@am__quote@
     1045@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po@am__quote@
    10411046@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BasicType.Po@am__quote@
    10421047@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-CommaExpr.Po@am__quote@
     
    25152520@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    25162521@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-Attribute.obj `if test -f 'SynTree/Attribute.cc'; then $(CYGPATH_W) 'SynTree/Attribute.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/Attribute.cc'; fi`
     2522
     2523SynTree/driver_cfa_cpp-BaseSyntaxNode.o: SynTree/BaseSyntaxNode.cc
     2524@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-BaseSyntaxNode.o -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.o `test -f 'SynTree/BaseSyntaxNode.cc' || echo '$(srcdir)/'`SynTree/BaseSyntaxNode.cc
     2525@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po
     2526@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.o' libtool=no @AMDEPBACKSLASH@
     2527@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2528@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.o `test -f 'SynTree/BaseSyntaxNode.cc' || echo '$(srcdir)/'`SynTree/BaseSyntaxNode.cc
     2529
     2530SynTree/driver_cfa_cpp-BaseSyntaxNode.obj: SynTree/BaseSyntaxNode.cc
     2531@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-BaseSyntaxNode.obj -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.obj `if test -f 'SynTree/BaseSyntaxNode.cc'; then $(CYGPATH_W) 'SynTree/BaseSyntaxNode.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/BaseSyntaxNode.cc'; fi`
     2532@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po
     2533@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.obj' libtool=no @AMDEPBACKSLASH@
     2534@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2535@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.obj `if test -f 'SynTree/BaseSyntaxNode.cc'; then $(CYGPATH_W) 'SynTree/BaseSyntaxNode.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/BaseSyntaxNode.cc'; fi`
    25172536
    25182537SynTree/driver_cfa_cpp-VarExprReplacer.o: SynTree/VarExprReplacer.cc
  • src/ResolvExpr/Resolver.cc

    r7e4b44db rbd06384  
    219219                assertf( expr, "expected a non-null expression." );
    220220
    221                 static CastExpr untyped( nullptr ); // cast to void
     221                auto untyped = new CastExpr{ expr }; // cast to void
    222222
    223223                // set up and resolve expression cast to void
    224                 untyped.arg = expr;
    225224                Alternative choice;
    226                 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, true );
     225                findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true );
    227226                CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr );
    228227                env = std::move( choice.env );
    229228
    230229                // clean up resolved expression
    231                 Expression * ret = castExpr->arg;
    232                 castExpr->arg = nullptr;
    233 
    234                 // unlink the arg so that it isn't deleted twice at the end of the program
    235                 untyped.arg = nullptr;
    236                 return ret;
     230                return castExpr->arg;
    237231        }
    238232
  • src/SymTab/Autogen.cc

    r7e4b44db rbd06384  
    588588                // must visit children (enum constants) to add them to the indexer
    589589                if ( enumDecl->has_body() ) {
    590                         EnumInstType enumInst( Type::Qualifiers(), enumDecl->get_name() );
    591                         enumInst.set_baseEnum( enumDecl );
    592                         EnumFuncGenerator gen( &enumInst, data, functionNesting, indexer );
     590                        auto enumInst = new EnumInstType{ Type::Qualifiers(), enumDecl->get_name() };
     591                        enumInst->set_baseEnum( enumDecl );
     592                        EnumFuncGenerator gen( enumInst, data, functionNesting, indexer );
    593593                        generateFunctions( gen, declsToAddAfter );
    594594                }
     
    598598                visit_children = false;
    599599                if ( structDecl->has_body() ) {
    600                         StructInstType structInst( Type::Qualifiers(), structDecl->name );
    601                         structInst.set_baseStruct( structDecl );
     600                        auto structInst = new StructInstType{ Type::Qualifiers(), structDecl->name };
     601                        structInst->set_baseStruct( structDecl );
    602602                        for ( TypeDecl * typeDecl : structDecl->parameters ) {
    603                                 structInst.parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) );
    604                         }
    605                         StructFuncGenerator gen( structDecl, &structInst, data, functionNesting, indexer );
     603                                structInst->parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) );
     604                        }
     605                        StructFuncGenerator gen( structDecl, structInst, data, functionNesting, indexer );
    606606                        generateFunctions( gen, declsToAddAfter );
    607607                } // if
     
    611611                visit_children = false;
    612612                if ( unionDecl->has_body()  ) {
    613                         UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() );
    614                         unionInst.set_baseUnion( unionDecl );
     613                        auto unionInst = new UnionInstType{ Type::Qualifiers(), unionDecl->get_name() };
     614                        unionInst->set_baseUnion( unionDecl );
    615615                        for ( TypeDecl * typeDecl : unionDecl->get_parameters() ) {
    616                                 unionInst.get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );
    617                         }
    618                         UnionFuncGenerator gen( unionDecl, &unionInst, data, functionNesting, indexer );
     616                                unionInst->get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );
     617                        }
     618                        UnionFuncGenerator gen( unionDecl, unionInst, data, functionNesting, indexer );
    619619                        generateFunctions( gen, declsToAddAfter );
    620620                } // if
     
    625625                if ( ! typeDecl->base ) return;
    626626
    627                 TypeInstType refType( Type::Qualifiers(), typeDecl->name, typeDecl );
    628                 TypeFuncGenerator gen( typeDecl, &refType, data, functionNesting, indexer );
     627                auto refType = new TypeInstType{ Type::Qualifiers(), typeDecl->name, typeDecl };
     628                TypeFuncGenerator gen( typeDecl, refType, data, functionNesting, indexer );
    629629                generateFunctions( gen, declsToAddAfter );
    630630
  • src/SynTree/GcTracer.h

    r7e4b44db rbd06384  
    2020#include "BaseSyntaxNode.h"
    2121#include "Expression.h"
     22#include "Type.h"
    2223
    2324#include "Common/GC.h"
     
    4748                maybeAccept( expr->env, *visitor );
    4849        }
     50
     51        void postvisit( PointerType* pty ) {
     52                maybeAccept( pty->dimension, *visitor );
     53        }
    4954};
    5055
  • src/SynTree/module.mk

    r7e4b44db rbd06384  
    4848       SynTree/TypeSubstitution.cc \
    4949       SynTree/Attribute.cc \
     50       SynTree/BaseSyntaxNode.cc \
    5051       SynTree/VarExprReplacer.cc
    5152
  • src/main.cc

    r7e4b44db rbd06384  
    244244                OPTPRINT( "validate" )
    245245                SymTab::validate( translationUnit, symtabp );
    246                 collect( translationUnit );
    247246                if ( symtabp ) return 0;
     247                collect( translationUnit );
    248248
    249249                if ( expraltp ) {
Note: See TracChangeset for help on using the changeset viewer.