Skip to content

Conversation

robertoraggi
Copy link
Owner

In this change we convert if, while and do statements using unstructured control flow. Obviously, the plan is to produce structured control flow but we will do that later.

int while_loop() {
  int x = 10;
  while (x) x = x - 1;
  return x;
}

int do_loop() {
  int x = 10;
  do x = x - 1;
  while (x);
  return x;
}

int cond1() {
  int x = 0;
  if (!x)
    x = 10;
  else
    x = 20;
  return x;
}

int cond2() {
  int x = 1;
  if (!x)
    x = 10;
  else
    x = 20;
  return x;
}
$ cxx x.c -emit-ir | mlir-translate -mlir-to-llvmir  |lli --entry-function=while_loop; echo $?
0

$ cxx x.c -emit-ir | mlir-translate -mlir-to-llvmir  |lli --entry-function=do_loop; echo $?
0

$ cxx x.c -emit-ir | mlir-translate -mlir-to-llvmir  |lli --entry-function=cond1; echo $?  
10

In this change we convert if, while and do statements
using unstructured control flow. Obviously, the plan
is to produce structured control flow but we will do
that later.

Signed-off-by: Roberto Raggi <[email protected]>
@robertoraggi robertoraggi merged commit 13aee87 into main Aug 3, 2025
9 checks passed
@robertoraggi robertoraggi deleted the sunny-muskox branch August 3, 2025 14:14
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