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

PS: SSA skeleton and various fixes #93

Merged
merged 7 commits into from
Sep 13, 2024
Merged

Conversation

MathiasVP
Copy link
Collaborator

@MathiasVP MathiasVP commented Sep 12, 2024

What is SSA?

This PR adds SSA analysis to Powershell by instantiating the shared SSA (static single-assignment) library which is also used by many of the existing CodeQL-supported languages (at least C#, Ruby, C++, Swift and Java once the draft PR is merged). SSA is the most classic compiler/static analysis representation of code. Basically, code such as:

int x = 42;
if(...) {
  x = x + 1;
}
use(x);

is converted to something that's equivalent to:

int x_1 = 42;
if(...) {
  x_2 = x_1 + 1;
}
x_3 = phi(x_1, x_2);
use(x_3);

where every single variable is defined exactly once in the source code.

If you are just interested in how SSA is achieved, I suggest only looking at 645db5b. It will be more obvious in a subsequent PR where I add some tests, though.

The commits

This PR contains slightly too many changes than I would like, but at least they're nicely separated into individual commits 😄

  • e99404a fixes a missing entry in the parent extensional. This was discovered during SSA development since I was missing some scopes for various variables.
  • 810978d adds a concept of a variable to the powershell libraries. This is needed because we need to talk about writes and reads to a variable, and so we need variables to define this 😂
  • 9107075 fixes up the CFG after the introduction of variables into the AST. Variables and Parameters are no longer instances of Ast, and the AST no longer has a top elements. So that's a bit annoying. If we want to fix this later we can create IPA types (i.e., newtypes) for all AST elements like many of the official CodeQL languages do (off the top of my head of I can think of C++, Swift, Ruby having done this in the past)
  • 8b4e065 and 645db5b adds the SSA library. This is a copy/paste of the Ruby version, and I have yet to add tests and actual implementations of many of the predicates. This will happen as the next step.
  • c26fdc3 fixes a couple of CFG issues. A couple of them was pointed out to me by @dilanbhalla when I introduced him to the CFG library. Thanks a lot, Dilan!
  • 9499972 accepts the various test changes. Most of these are from earlier PRs where I forgot to run tests 😭

@MathiasVP MathiasVP force-pushed the powershell-ssa-skeleton branch from fb9465d to 9499972 Compare September 13, 2024 11:18
@MathiasVP MathiasVP merged commit 4343d6b into main Sep 13, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

1 participant