rui314 / 8cc

A Small C Compiler
MIT License
6.13k stars 740 forks source link

Handle # line directive #32

Closed andrewchambers closed 9 years ago

andrewchambers commented 9 years ago

I don't think 8cc handles line directives currently, so you can't pass code preprocessed by gcc.

rui314 commented 9 years ago

We do have one. Look at read_line() in cpp.c. I haven't actually tested that against GCC output though.

andrewchambers commented 9 years ago

Ah ok, It was failing badly on my PC, I'll reduce the test case and maybe fix.

andrewchambers commented 9 years ago

Ah, my gcc isn't emitting #line,

here is an example of what gcc is spitting out:

# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "foo.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 29 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/_ansi.h" 1 3 4
# 15 "/usr/include/_ansi.h" 3 4
# 1 "/usr/include/newlib.h" 1 3 4
# 16 "/usr/include/_ansi.h" 2 3 4
# 1 "/usr/include/sys/config.h" 1 3 4
andrewchambers commented 9 years ago

here is a reference to what they mean: https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html

rui314 commented 9 years ago

Okay this is a GNU extension to the language. It looks interesting, I'll implement that later. At this moment I got to focus on the new backend, so please slow down a bit.

andrewchambers commented 9 years ago

No problem. I'll track these on my own fork then test them again after that branch is integrated.