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

[Project] C Backend #51

Open
o- opened this issue Feb 9, 2017 · 2 comments
Open

[Project] C Backend #51

o- opened this issue Feb 9, 2017 · 2 comments

Comments

@o-
Copy link
Contributor

o- commented Feb 9, 2017

Compile sourir to C.

The translation should be relatively straight forward. To give you an idea, lets consider the following program:

x = read()
while x > 10:
  x/2
print x

In sourir this would be somthing like

  mut x
  read x
l:
  br x > 10 b e
b:
  x <- x / 2
  goto l
e:
  print x

Which can be easily compiled to the following C program:

void main() {
l1: {} int x;
l2: { char t[20]; gets(&t); x = atoi(t); }
l3: { if (x > 10) {goto l4;} else {goto l6;} }
l4: { x = x / 2; }
l5: { goto l3; }
l6: { printf ("%d\n", x); }
}
@gasche
Copy link
Collaborator

gasche commented Feb 10, 2017

Really subtle trolling of C programmers, the buffer overflow in the compiled code example ;-)

@o-
Copy link
Contributor Author

o- commented Feb 10, 2017

writing the exploit is an exercise left to the reader

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

2 participants