@@ -34,6 +34,8 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
3434 final override Function getFunction ( ) { result = func }
3535
3636 final override TranslatedElement getChild ( int id ) {
37+ id = - 4 and result = getReadEffects ( )
38+ or
3739 id = - 3 and result = getConstructorInitList ( )
3840 or
3941 id = - 2 and result = getBody ( )
@@ -53,6 +55,8 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
5355
5456 final private TranslatedStmt getBody ( ) { result = getTranslatedStmt ( func .getEntryPoint ( ) ) }
5557
58+ final private TranslatedReadEffects getReadEffects ( ) { result = getTranslatedReadEffects ( func ) }
59+
5660 final private TranslatedParameter getParameter ( int index ) {
5761 result = getTranslatedParameter ( func .getParameter ( index ) )
5862 }
@@ -113,8 +117,11 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
113117 child = getBody ( ) and
114118 result = getReturnSuccessorInstruction ( )
115119 or
120+ child = getDestructorDestructionList ( ) and
121+ result = getReadEffects ( ) .getFirstInstruction ( )
122+ or
116123 (
117- child = getDestructorDestructionList ( ) and
124+ child = getReadEffects ( ) and
118125 if getReturnType ( ) instanceof VoidType
119126 then result = getInstruction ( ReturnTag ( ) )
120127 else result = getInstruction ( ReturnValueAddressTag ( ) )
@@ -531,3 +538,101 @@ class TranslatedDestructorDestructionList extends TranslatedElement,
531538 )
532539 }
533540}
541+
542+ TranslatedReadEffects getTranslatedReadEffects ( Function func ) { result .getAST ( ) = func }
543+
544+ class TranslatedReadEffects extends TranslatedElement , TTranslatedReadEffects {
545+ Function func ;
546+
547+ TranslatedReadEffects ( ) { this = TTranslatedReadEffects ( func ) }
548+
549+ override Locatable getAST ( ) { result = func }
550+
551+ override Function getFunction ( ) { result = func }
552+
553+ override string toString ( ) { result = "read effects: " + func .toString ( ) }
554+
555+ override TranslatedElement getChild ( int id ) {
556+ result = getTranslatedReadEffect ( func .getParameter ( id ) )
557+ }
558+
559+ override Instruction getFirstInstruction ( ) {
560+ if exists ( getAChild ( ) )
561+ then
562+ result = min ( TranslatedReadEffect child , int id | child = getChild ( id ) | child order by id )
563+ .getFirstInstruction ( )
564+ else result = getParent ( ) .getChildSuccessor ( this )
565+ }
566+
567+ override Instruction getChildSuccessor ( TranslatedElement child ) {
568+ exists ( int id | child = getChild ( id ) |
569+ if exists ( TranslatedReadEffect child2 , int id2 | id2 > id and child2 = getChild ( id2 ) )
570+ then
571+ result = min ( TranslatedReadEffect child2 , int id2 |
572+ child2 = getChild ( id2 ) and id2 > id
573+ |
574+ child2 order by id2
575+ ) .getFirstInstruction ( )
576+ else result = getParent ( ) .getChildSuccessor ( this )
577+ )
578+ }
579+
580+ override predicate hasInstruction (
581+ Opcode opcode , InstructionTag tag , Type resultType , boolean isGLValue
582+ ) {
583+ none ( )
584+ }
585+
586+ override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) { none ( ) }
587+ }
588+
589+ private TranslatedReadEffect getTranslatedReadEffect ( Parameter param ) { result .getAST ( ) = param }
590+
591+ class TranslatedReadEffect extends TranslatedElement , TTranslatedReadEffect {
592+ Parameter param ;
593+
594+ TranslatedReadEffect ( ) { this = TTranslatedReadEffect ( param ) }
595+
596+ override Locatable getAST ( ) { result = param }
597+
598+ override string toString ( ) { result = "read effect: " + param .toString ( ) }
599+
600+ override TranslatedElement getChild ( int id ) { none ( ) }
601+
602+ override Instruction getChildSuccessor ( TranslatedElement child ) { none ( ) }
603+
604+ override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind edge ) {
605+ tag = OnlyInstructionTag ( ) and
606+ edge = gotoEdge ( ) and
607+ result = getParent ( ) .getChildSuccessor ( this )
608+ }
609+
610+ override Instruction getFirstInstruction ( ) { result = getInstruction ( OnlyInstructionTag ( ) ) }
611+
612+ override Function getFunction ( ) { result = param .getFunction ( ) }
613+
614+ override predicate hasInstruction (
615+ Opcode opcode , InstructionTag tag , Type resultType , boolean isGLValue
616+ ) {
617+ opcode instanceof Opcode:: ReturnIndirection and
618+ tag = OnlyInstructionTag ( ) and
619+ resultType instanceof VoidType and
620+ isGLValue = false
621+ }
622+
623+ final override Instruction getInstructionOperand ( InstructionTag tag , OperandTag operandTag ) {
624+ tag = OnlyInstructionTag ( ) and
625+ operandTag = sideEffectOperand ( ) and
626+ result = getTranslatedFunction ( getFunction ( ) ) .getUnmodeledDefinitionInstruction ( )
627+ or
628+ tag = OnlyInstructionTag ( ) and
629+ operandTag = addressOperand ( ) and
630+ result = getTranslatedParameter ( param ) .getInstruction ( InitializerIndirectAddressTag ( ) )
631+ }
632+
633+ final override Type getInstructionOperandType ( InstructionTag tag , TypedOperandTag operandTag ) {
634+ tag = OnlyInstructionTag ( ) and
635+ operandTag = sideEffectOperand ( ) and
636+ result instanceof UnknownType
637+ }
638+ }
0 commit comments