Changeset 7f5566b for src/SynTree


Ignore:
Timestamp:
Jul 30, 2015, 3:56:18 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
093f1a0
Parents:
51b986f
Message:

asm statement, memory leaks

Location:
src/SynTree
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Constant.cc

    r51b986f r7f5566b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jun 10 14:41:03 2015
    13 // Update Count     : 8
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 30 15:18:38 2015
     13// Update Count     : 12
    1414//
    1515
     
    2222Constant::Constant( Type *type_, std::string value_ ) : type( type_ ), value( value_ ) {}
    2323
    24 Constant::~Constant() {}
     24Constant::Constant( const Constant &other ) {
     25        type = other.type->clone();
     26        value = other.value;
     27}
    2528
    26 Constant *Constant::clone() const { return 0; }
     29Constant::~Constant() { delete type; }
     30
     31Constant *Constant::clone() const { assert( false ); return 0; }
    2732
    2833void Constant::print( std::ostream &os ) const {
  • src/SynTree/Constant.h

    r51b986f r7f5566b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 08:46:37 2015
    13 // Update Count     : 2
     12// Last Modified On : Thu Jul 30 15:19:16 2015
     13// Update Count     : 5
    1414//
    1515
     
    2424  public:
    2525        Constant( Type *type, std::string value );
     26        Constant( const Constant &other );
    2627        virtual ~Constant();
    2728
  • src/SynTree/Expression.cc

    r51b986f r7f5566b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jun  7 08:40:46 2015
    13 // Update Count     : 16
     12// Last Modified On : Tue Jul 28 16:27:17 2015
     13// Update Count     : 22
    1414//
    1515
     
    3838Expression::~Expression() {
    3939        delete env;
    40         // delete argName;      // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
     40        delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
    4141        deleteAll( results );
    4242}
     
    332332}
    333333
     334void AsmExpr::print( std::ostream &os, int indent ) const {
     335        os << "Asm Expression: " << std::endl;
     336        if ( inout ) inout->print( os, indent + 2 );
     337        if ( constraint ) constraint->print( os, indent + 2 );
     338        if ( operand ) operand->print( os, indent + 2 );
     339}
     340
    334341void UntypedValofExpr::print( std::ostream &os, int indent ) const {
    335342        os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;
  • src/SynTree/Expression.h

    r51b986f r7f5566b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jun  7 22:03:44 2015
    13 // Update Count     : 4
     12// Last Modified On : Fri Jul 24 13:49:28 2015
     13// Update Count     : 18
    1414//
    1515
     
    3030
    3131        std::list<Type *>& get_results() { return results; }
    32         void add_result(Type *t);
     32        void add_result( Type *t );
    3333
    3434        TypeSubstitution *get_env() const { return env; }
     
    446446};
    447447
     448// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
     449class AsmExpr : public Expression {
     450  public:
     451        AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
     452        virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
     453
     454        Expression *get_inout() const { return inout; }
     455        void set_inout( Expression *newValue ) { inout = newValue; }
     456
     457        ConstantExpr *get_constraint() const { return constraint; }
     458        void set_constraint( ConstantExpr *newValue ) { constraint = newValue; }
     459
     460        Expression *get_operand() const { return operand; }
     461        void set_operand( Expression *newValue ) { operand = newValue; }
     462
     463        virtual AsmExpr *clone() const { return new AsmExpr( *this ); }
     464        virtual void accept( Visitor &v ) { v.visit( this ); }
     465        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     466        virtual void print( std::ostream &os, int indent = 0 ) const;
     467  private:
     468        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
     469        Expression *inout;
     470        ConstantExpr *constraint;
     471        Expression *operand;
     472};
     473
    448474// ValofExpr represents a GCC 'lambda expression'
    449475class UntypedValofExpr : public Expression {
  • src/SynTree/Mutator.cc

    r51b986f r7f5566b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 16 16:10:54 2015
    13 // Update Count     : 3
     12// Last Modified On : Sat Jul 25 19:21:33 2015
     13// Update Count     : 11
    1414//
    1515
     
    9595}
    9696
     97Statement *Mutator::mutate( AsmStmt *asmStmt ) {
     98        asmStmt->set_instruction( maybeMutate( asmStmt->get_instruction(), *this ) );
     99        mutateAll( asmStmt->get_output(), *this );
     100        mutateAll( asmStmt->get_input(), *this );
     101        mutateAll( asmStmt->get_clobber(), *this );
     102        return asmStmt;
     103}
     104
    97105Statement *Mutator::mutate( IfStmt *ifStmt ) {
    98106        ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
     
    291299        typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
    292300        return typeExpr;
     301}
     302
     303Expression *Mutator::mutate( AsmExpr *asmExpr ) {
     304        asmExpr->set_inout( maybeMutate( asmExpr->get_inout(), *this ) );
     305        asmExpr->set_constraint( maybeMutate( asmExpr->get_constraint(), *this ) );
     306        asmExpr->set_operand( maybeMutate( asmExpr->get_operand(), *this ) );
     307        return asmExpr;
    293308}
    294309
  • src/SynTree/Mutator.h

    r51b986f r7f5566b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 13 18:14:47 2015
    13 // Update Count     : 5
     12// Last Modified On : Thu Jul 23 23:24:18 2015
     13// Update Count     : 7
    1414//
    1515#include <cassert>
     
    3737        virtual CompoundStmt* mutate( CompoundStmt *compoundStmt );
    3838        virtual Statement* mutate( ExprStmt *exprStmt );
     39        virtual Statement* mutate( AsmStmt *asmStmt );
    3940        virtual Statement* mutate( IfStmt *ifStmt );
    4041        virtual Statement* mutate( WhileStmt *whileStmt );
     
    7071        virtual Expression* mutate( SolvedTupleExpr *tupleExpr );
    7172        virtual Expression* mutate( TypeExpr *typeExpr );
     73        virtual Expression* mutate( AsmExpr *asmExpr );
    7274        virtual Expression* mutate( UntypedValofExpr *valofExpr );
    7375
  • src/SynTree/Statement.cc

    r51b986f r7f5566b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jul 15 14:57:40 2015
    13 // Update Count     : 27
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 25 12:19:50 2015
     13// Update Count     : 53
    1414//
    1515
     
    4242        expr->print( os, indent + 2 );
    4343}
     44
     45
     46AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *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 ) {}
     47
     48AsmStmt::~AsmStmt() {
     49        delete instruction;
     50        deleteAll( output );
     51        deleteAll( input );
     52        deleteAll( clobber );
     53}
     54
     55void AsmStmt::print( std::ostream &os, int indent ) const {
     56        os << "Assembler Statement:" << endl;
     57        os << std::string( indent, ' ' ) << "instruction: " << endl << std::string( indent, ' ' );
     58        instruction->print( os, indent + 2 );
     59        if ( ! output.empty() ) {
     60                os << endl << std::string( indent, ' ' ) << "output: " << endl;
     61                printAll( output, os, indent + 2 );
     62        } // if
     63        if ( ! input.empty() ) {
     64                os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' );
     65                printAll( input, os, indent + 2 );
     66        } // if
     67        if ( ! clobber.empty() ) {
     68                os << std::string( indent, ' ' ) << "clobber: " << endl;
     69                printAll( clobber, os, indent + 2 );
     70        } // if
     71}
     72
    4473
    4574const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
  • src/SynTree/Statement.h

    r51b986f r7f5566b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jul 14 12:14:54 2015
    13 // Update Count     : 24
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 25 18:25:37 2015
     13// Update Count     : 44
    1414//
    1515
     
    7070};
    7171
     72class AsmStmt : public Statement {
     73  public:
     74        AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
     75        virtual ~AsmStmt();
     76
     77        bool get_voltile() { return voltile; }
     78        void set_voltile( bool newValue ) { voltile = newValue; }
     79        ConstantExpr *get_instruction() { return instruction; }
     80        void set_instruction( ConstantExpr *newValue ) { instruction = newValue; }
     81        std::list<Expression *> &get_output() { return output; }
     82        void set_output( const std::list<Expression *> &newValue ) { output = newValue; }
     83        std::list<Expression *> &get_input() { return input; }
     84        void set_input( const std::list<Expression *> &newValue ) { input = newValue; }
     85        std::list<ConstantExpr *> &get_clobber() { return clobber; }
     86        void set_clobber( const std::list<ConstantExpr *> &newValue ) { clobber = newValue; }
     87        std::list<Label> &get_gotolabels() { return gotolabels; }
     88        void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; }
     89
     90        virtual AsmStmt *clone() const { return new AsmStmt( *this ); }
     91        virtual void accept( Visitor &v ) { v.visit( this ); }
     92        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     93        virtual void print( std::ostream &os, int indent = 0 ) const;
     94  private:
     95        bool voltile;
     96        ConstantExpr *instruction;
     97        std::list<Expression *> output, input;
     98        std::list<ConstantExpr *> clobber;
     99        std::list<Label> gotolabels;
     100};
     101
    72102class IfStmt : public Statement {
    73103  public:
     
    100130        void set_condition( Expression *newValue ) { condition = newValue; }
    101131
    102         std::list<Statement *>& get_branches() { return branches; }
     132        std::list<Statement *> & get_branches() { return branches; }
    103133        void add_case( CaseStmt * );
    104134
  • src/SynTree/SynTree.h

    r51b986f r7f5566b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 10:58:22 2015
    13 // Update Count     : 1
     12// Last Modified On : Thu Jul 23 23:25:04 2015
     13// Update Count     : 3
    1414//
    1515
     
    4040class CompoundStmt;
    4141class ExprStmt;
     42class AsmStmt;
    4243class IfStmt;
    4344class WhileStmt;
     
    7576class SolvedTupleExpr;
    7677class TypeExpr;
     78class AsmExpr;
    7779class UntypedValofExpr;
    7880
  • src/SynTree/Visitor.cc

    r51b986f r7f5566b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jul 14 12:31:03 2015
    13 // Update Count     : 3
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jul 24 16:11:05 2015
     13// Update Count     : 15
    1414//
    1515
     
    8282}
    8383
     84void Visitor::visit( AsmStmt *asmStmt ) {
     85        maybeAccept( asmStmt->get_instruction(), *this );
     86        acceptAll( asmStmt->get_output(), *this );
     87        acceptAll( asmStmt->get_input(), *this );
     88        acceptAll( asmStmt->get_clobber(), *this );
     89}
     90
    8491void Visitor::visit( IfStmt *ifStmt ) {
    8592        maybeAccept( ifStmt->get_condition(), *this );
     
    246253}
    247254
     255void Visitor::visit( AsmExpr *asmExpr ) {
     256        maybeAccept( asmExpr->get_inout(), *this );
     257        maybeAccept( asmExpr->get_constraint(), *this );
     258        maybeAccept( asmExpr->get_operand(), *this );
     259}
     260
    248261void Visitor::visit( UntypedValofExpr *valofExpr ) {
    249262        acceptAll( valofExpr->get_results(), *this );
     
    282295
    283296void Visitor::visit( StructInstType *aggregateUseType ) {
    284         visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     297        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
    285298}
    286299
    287300void Visitor::visit( UnionInstType *aggregateUseType ) {
    288         visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     301        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
    289302}
    290303
    291304void Visitor::visit( EnumInstType *aggregateUseType ) {
    292         visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     305        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
    293306}
    294307
    295308void Visitor::visit( ContextInstType *aggregateUseType ) {
    296         visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     309        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
    297310        acceptAll( aggregateUseType->get_members(), *this );
    298311}
    299312
    300313void Visitor::visit( TypeInstType *aggregateUseType ) {
    301         visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     314        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
    302315}
    303316
  • src/SynTree/Visitor.h

    r51b986f r7f5566b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 11:15:55 2015
    13 // Update Count     : 2
     12// Last Modified On : Thu Jul 23 23:22:23 2015
     13// Update Count     : 4
    1414//
    1515
     
    3737        virtual void visit( CompoundStmt *compoundStmt );
    3838        virtual void visit( ExprStmt *exprStmt );
     39        virtual void visit( AsmStmt *asmStmt );
    3940        virtual void visit( IfStmt *ifStmt );
    4041        virtual void visit( WhileStmt *whileStmt );
     
    7071        virtual void visit( SolvedTupleExpr *tupleExpr );
    7172        virtual void visit( TypeExpr *typeExpr );
     73        virtual void visit( AsmExpr *asmExpr );
    7274        virtual void visit( UntypedValofExpr *valofExpr );
    7375
Note: See TracChangeset for help on using the changeset viewer.