1

I am writing a code in c#.

In the code there are various IF conditions. I want to pass these conditions to z3 constraint solver and check its satisfiability and get the values that makes it satifiable. (I make use of these values further in my code)

If I take a IF condition in the code and write its equivalent assert in z3 syntax then it works fine. But I want to generalize means given a statement in c# I want to generate its corresponding statement in z3 syntax.

Is there anyway I can do that?

usr
  • 168,620
  • 35
  • 240
  • 369
Poorva
  • 31
  • 2

1 Answers1

0

The C# language does not provide the necessary hooks so that you can detect the presence of an if statement at runtime. What you can't detect you can't tell to Z3.

You could use Roslyn to parse a string containing C# code into an AST and translate that to Z3. That's probably not that hard to do for simple cases. This breaks down for cyclic control flow. You can probably make it work for the common acyclic constructs like variables, operators, if, switch.

usr
  • 168,620
  • 35
  • 240
  • 369