Changeset b8ab91a


Ignore:
Timestamp:
Nov 5, 2021, 1:46:46 PM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
21fe17f
Parents:
77c01ec
Message:

Fix Labels pass translated. This is fix label, mult-level exit and label generator.

Location:
src
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r77c01ec rb8ab91a  
    131131        // declared type, derived from parameter declarations
    132132        ptr<FunctionType> type;
     133        /// Null for the forward declaration of a function.
    133134        ptr<CompoundStmt> stmts;
    134135        std::vector< ptr<Expr> > withExprs;
  • src/AST/Stmt.hpp

    r77c01ec rb8ab91a  
    175175class CaseStmt final : public Stmt {
    176176public:
     177        /// Null for the default label.
    177178        ptr<Expr> cond;
    178179        std::vector<ptr<Stmt>> stmts;
  • src/ControlStruct/LabelGenerator.cc

    r77c01ec rb8ab91a  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 11 22:23:20 2019
    13 // Update Count     : 15
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Nov  1 12:21:00 2021
     13// Update Count     : 16
    1414//
    1515
     
    1919
    2020#include "LabelGenerator.h"
     21
     22#include "AST/Attribute.hpp"
     23#include "AST/Label.hpp"
     24#include "AST/Stmt.hpp"
    2125#include "SynTree/Attribute.h"  // for Attribute
    2226#include "SynTree/Label.h"      // for Label, operator<<
     
    4347                return l;
    4448        }
     49
     50LabelGenerator_new * LabelGenerator_new::labelGenerator = nullptr;
     51
     52LabelGenerator_new * LabelGenerator_new::getGenerator() {
     53        if ( nullptr == labelGenerator ) {
     54                labelGenerator = new LabelGenerator_new();
     55        }
     56        return labelGenerator;
     57}
     58
     59ast::Label LabelGenerator_new::newLabel(
     60                const std::string & suffix, const ast::Stmt * stmt ) {
     61        assert( stmt );
     62
     63        std::ostringstream os;
     64        os << "__L" << current++ << "__" << suffix;
     65        if ( stmt && !stmt->labels.empty() ) {
     66                os << "_" << stmt->labels.front() << "__";
     67        }
     68        ast::Label ret_label( stmt->location, os.str() );
     69        ret_label.attributes.push_back( new ast::Attribute( "unused" ) );
     70        return ret_label;
     71}
     72
    4573} // namespace ControlStruct
    4674
  • src/ControlStruct/LabelGenerator.h

    r77c01ec rb8ab91a  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:20:14 2017
    13 // Update Count     : 6
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Nov  1 12:19:00 2021
     13// Update Count     : 7
    1414//
    1515
     
    2121
    2222class Statement;
     23namespace ast {
     24        class Stmt;
     25        class Label;
     26}
    2327
    2428namespace ControlStruct {
     
    3539                static LabelGenerator *labelGenerator;
    3640        };
     41
     42class LabelGenerator_new {
     43        int current;
     44        static LabelGenerator_new *labelGenerator;
     45
     46        LabelGenerator_new() : current(0) {}
     47public:
     48        static LabelGenerator_new *getGenerator();
     49
     50        ast::Label newLabel( const std::string& suffix, const ast::Stmt * stmt );
     51        void reset() { current = 0; }
     52        void rewind() { --current; }
     53};
     54
    3755} // namespace ControlStruct
    3856
  • src/ControlStruct/module.mk

    r77c01ec rb8ab91a  
    1818        ControlStruct/ExceptDecl.cc \
    1919        ControlStruct/ExceptDecl.h \
     20        ControlStruct/FixLabels.cpp \
     21        ControlStruct/FixLabels.hpp \
    2022        ControlStruct/ForExprMutator.cc \
    2123        ControlStruct/ForExprMutator.h \
     
    2628        ControlStruct/MLEMutator.cc \
    2729        ControlStruct/MLEMutator.h \
     30        ControlStruct/MultiLevelExit.cpp \
     31        ControlStruct/MultiLevelExit.hpp \
    2832        ControlStruct/Mutate.cc \
    2933        ControlStruct/Mutate.h
  • src/main.cc

    r77c01ec rb8ab91a  
    5353#include "ControlStruct/ExceptDecl.h"       // for translateExcept
    5454#include "ControlStruct/ExceptTranslate.h"  // for translateEHM
     55#include "ControlStruct/FixLabels.hpp"      // for fixLabels
    5556#include "ControlStruct/Mutate.h"           // for mutate
    5657#include "GenPoly/Box.h"                    // for box
     
    334335
    335336                PASS( "Translate Throws", ControlStruct::translateThrows( translationUnit ) );
    336                 PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
    337337
    338338                CodeTools::fillLocations( translationUnit );
     
    347347                        forceFillCodeLocations( transUnit );
    348348
     349                        PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) );
    349350                        PASS( "Fix Names", CodeGen::fixNames( transUnit ) );
    350351                        PASS( "Gen Init", InitTweak::genInit( transUnit ) );
     
    383384                        translationUnit = convert( move( transUnit ) );
    384385                } else {
     386                        PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
    385387                        PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
    386388                        PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
Note: See TracChangeset for help on using the changeset viewer.