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

Multi-file compilation? #56

Open
adrianparvino opened this issue Nov 25, 2018 · 3 comments
Open

Multi-file compilation? #56

adrianparvino opened this issue Nov 25, 2018 · 3 comments

Comments

@adrianparvino
Copy link

Is there a way to build a single output from 2 files?

@shinh
Copy link
Owner

shinh commented Nov 26, 2018

There is no linker. However, because EIR is a very simple text-based format, just concatenating EIR files may just work. Suppose you have these two files:

$ cat main.c
void foo();
int main() {
    foo();
}
$ cat foo.c
#include <stdio.h>
void foo() {
    puts("Hello, world!");
}

and you can do

$ out/8cc -S -I. -Ilibc -Iout foo.c -o foo.eir
$ out/8cc -S -I. -Ilibc -Iout main.c -o main.eir
$ cat foo.eir main.eir > linked.eir
$ out/elc linked.eir -rb linked.eir > linked.rb
$ ruby linked.rb
Hello, world!

Note that, as cat is not a linker, it cannot raise an error for symbols defined multiple times.

@shinh
Copy link
Owner

shinh commented Nov 26, 2018

I realized the above wouldn't work for most cases since symbols generated by the compiler (e.g., .L1 for loops) will conflict with each other. Probably, the best workaround we can do today would be just concatenating all C source code to a single C source code before using the compiler. For example, see out/8cc.c after running make test-rb-full

@adrianparvino
Copy link
Author

@shinh I am currently working on using clang as a linker, producing LLVM, and https://github.com/JuliaComputing/llvm-cbe to output C from LLVM, then compiling with ELVM.

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