Skip to content

anstadnik/goto-elimination

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Goto elimination

This repository contains code for Taming Control Flow A Structured Approach to Eliminating Goto Statements.

It's a pet project, so I used advanced tools. For an easy usage I provide a Dockerfile.

Usage

Build docker:

docker build -t goto_elimination .

Run docker:

docker run -it -v $(pwd)/inputs:/tmp/inputs goto_elimination:latest /tmp/inputs/elim_while.txt

Inputs

This code requires inputs in a form of a Mermaid. The following example shows all basic building blocks of the app (assignment, conditional, print).

Example input:

graph TB
    A[a=0] --> B[a=a+1]
    B --> C{a < 10}
    C -->|True| B
    C -->|False| D(a)

The same input, but converted into a diagram:

graph TB
    A[a=0] --> B[a=a+1]
    B --> C{a < 10}
    C -->|True| B
    C -->|False| D(a)
Loading

Parsed code:

#include <iostream>
using namespace std;

int main() {
int a=0;
/***************
*  Statement   *
***************/

A:                       a=0;
B:                       a=a+1;
C:                       if (a<10) { goto B; }
D:                       cout << a << endl;
}

Code with eliminated gotos:

#include <iostream>
using namespace std;

int main() {
int a=0;
int _elim_C_f_=0;
/***************
*  Statement   *
***************/

A:                       a=0;
_elim_C_f_t_:            _elim_C_f_=1;
_elim_C:                 while (a<10 || _elim_C_f_) {
_elim_C_f_f_:              _elim_C_f_=0;
B:                         a=a+1;
                         }
C:                       (void)1; // Empty
D:                       cout << a << endl;
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages