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

Add C++ Template Metaprogramming Backend #39

Merged
merged 2 commits into from
Feb 25, 2017

Conversation

keiichiw
Copy link
Contributor

@keiichiw keiichiw commented Feb 25, 2017

I added C++ template metaprogramming(TMP) backend.
You can test this backend by the following command:

$ CPP_TEMPLATE=1 make cpp_template

This backend generates a C++ program that performs a compile-time computation like C++14 constexpr backend.
However, TMP is much more restricted than C++14 constexpr.

The largest restriction is that a huge amount of memory is needed to compile a program generated by this backend.
For example, g++ uses about 3GB memory to compile a C++ template program translated from a simple program:

$ cat hello.c
#include <stdio.h>
int main () {
  printf("Hello World!\n");
  return 0;
}
$ out/8cc -S ./hello.c -o hello.eir -Ilibc
$ out/elc -cpp_template hello.eir >hello.cpp
$ g++ -std=c++11 ./hello.cpp -o hello.exe     # g++ uses about 3GB memory here
$ ./hello.exe
Hello World!

The more complex program you want to run, the more memory is needed.
Thus, unfortunately, 8cc translated by this backend does not work at all.

@shinh shinh merged commit 95af9e7 into shinh:master Feb 25, 2017
@shinh
Copy link
Owner

shinh commented Feb 25, 2017

Thanks!

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.

2 participants