Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the A1 #4

Open
Shmily8421 opened this issue Jul 3, 2022 · 7 comments
Open

About the A1 #4

Shmily8421 opened this issue Jul 3, 2022 · 7 comments

Comments

@Shmily8421
Copy link

How could I get the value from statement? The Lvalueclass and the Rvalueclass is not a Varclass
image

@DianQK
Copy link

DianQK commented Jul 3, 2022

@Shmily8421
RValue is not always Var, you can check Exp.getUses().

'a + b'.getUses() -> [Var, Var].

@Shmily8421
Copy link
Author

Emmmm, Could u say that in more details?

@DianQK
Copy link

DianQK commented Jul 3, 2022

@Shmily8421

2.1 Tai-e Classes You Need to Know

The RValue may be a Var, a BinaryExp, or another type.
a + b is a BinaryExp (also AbstractBinaryExp):

You can get this code from dependencies.jar:

abstract class AbstractBinaryExp implements BinaryExp {
    public List<RValue> getUses() {
        return List.of(this.operand1, this.operand2);
    }
}

Maybe we should assume that the AST is brought directly into the IR?

  • a = b is Var = Var
  • a = b + c is Var = BinaryExp, this can be extended as Var = Var Op Var

btw, I don't know the design details of IR. because the getUses is a method of the Exp and I use recursion to handle this.

Read the code and comments in the project with patience and good luck. :)

@Shmily8421
Copy link
Author

Okay, I can understand the AST logic.
But as you said, the definition of these interface class is quite complex, so that I don't know how to get the Var in this sentence through the Stmt class.

@MirageLyu
Copy link

Check the class pascal.taie.ir.stmt.AbstractStmt. There are 7 overrides of its method getUses(), and some of these override implementations reused Exp.getUses(). In most cases the getUses() actually returns a List of Var...while i didn't statically check all the cases, i have no idea if possible that the return List of getUses() contains objects of other subclasses of Rvalue instead of Var...maybe print the type during execution is a way to find it.

So, maybe you need to check if (rvalue instanceof Var), then force cast the rvalue to Var if true.

@BruceJiang066
Copy link

How could I get the value from statement? The Lvalueclass and the Rvalueclass is not a Varclass image

boolean flag=(temp!=in) ,this statement must use the " equals()" to replace the " != "

@cyk2018
Copy link

cyk2018 commented May 28, 2023

How could I get the value from statement? The Lvalueclass and the Rvalueclass is not a Varclass image

boolean flag=(temp!=in) ,this statement must use the " equals()" to replace the " != "

you can also use the method "union" whose result type is boolean (true when the FactSet is changed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants