c2ats
c2ats copied to clipboard
Split output into sats files
First step, the output should be split into following:
- c2ats_out.sats which includes typedef, macdef, (template) function declaration, #define, staload, %{}.
- c2ats_out_tmpl.sats which includes template function definition, staload.
Read carefully following:
https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html
Need sub-program to seek C language headers and build tree.
http://qiita.com/akachochin/items/71536ca5183b1f7c8db1
Include path can be found at following:
$ gcc -Q -v example/hello/example.h
--snip--
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/6/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
--snip--
Header search is ordered. It means at above example, if you do #include <stdio.h>....
- First, try to find /usr/lib/gcc/x86_64-linux-gnu/6/include/stdio.h
- Next, try /usr/local/include/stdio.h
- ...
- Finally, try /usr/include/stdio.h
Need to drop unused headers from the tree.
Should be consider #include_next...
I think we can drop supporting #include_next:
$ grep -r "^#include_next" /usr/include
/usr/include/bsd/stdio.h:#include_next <stdio.h>
/usr/include/bsd/err.h:#include_next <err.h>
/usr/include/bsd/sys/cdefs.h:#include_next <sys/cdefs.h>
/usr/include/bsd/sys/endian.h:#include_next <endian.h>
/usr/include/bsd/sys/poll.h:#include_next <sys/poll.h>
/usr/include/bsd/stdlib.h:#include_next <stdlib.h>
/usr/include/bsd/unistd.h:#include_next <unistd.h>
/usr/include/bsd/getopt.h:#include_next <getopt.h>
/usr/include/bsd/string.h:#include_next <string.h>
/usr/include/bsd/wchar.h:#include_next <wchar.h>
/usr/include/c++/6/cstdlib:#include_next <stdlib.h>
/usr/include/c++/6/cmath:#include_next <math.h>
And also, NetBSD src/sys does not use it.
Support # include:
$ grep -r getopt.h /usr/include/
/usr/include/stdio.h:# include <getopt.h>
Slow?
total time = 2.90 secs (2902 ticks @ 1000 us, 1 processor)
total alloc = 4,791,124,296 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
lexC Language.C.Parser.Lexer 20.1 22.7
createSATS.go' Language.C2ATS.HeaderTree 12.3 10.9
splitFlatGlobal'.mFile' Language.C2ATS.Process 4.8 0.2
injectForwardDecl.f.fds Language.C2ATS.Process 4.7 0.1
injectForwardDecl.f.is'' Language.C2ATS.Process 4.4 0.4
lookupGlobal Language.C.Analysis.NameSpaceMap 3.2 0.0
injectIncludes.go.files' Language.C2ATS.Process 3.1 0.0
injectIncludes.go Language.C2ATS.Process 2.8 0.3
tType Language.C.Analysis.DeclAnalysis 2.8 2.2
analyseVarDecl Language.C.Analysis.DeclAnalysis 2.0 1.4
injectIncludes.f Language.C2ATS.Process 2.0 3.0
headerTree Language.C2ATS.HeaderTree 1.9 1.9
analyseDecl Language.C.Analysis.AstAnalysis 1.8 1.1
analyseVarDecl' Language.C.Analysis.DeclAnalysis 1.7 0.9
canonicalTypeSpec Language.C.Analysis.DeclAnalysis 1.5 1.0
realPath Language.C2ATS.FlatGlobalDecl 1.5 31.9
includeHeaders.incs Language.C2ATS.HeaderTree 1.3 2.9
injectIncludes.getFile Language.C2ATS.Process 1.1 2.1
nodeInfo Language.C2ATS.FlatGlobalDecl 1.0 0.0
hPunctuate Language.C2ATS.Pretty 0.7 1.2
readFileHeader' Language.C2ATS.HeaderTree 0.4 1.9
Use ByteString.
Ummm.... How to fix it?
$ make
c2ats gen -o out example.h
dirname `find out -name example.sats` | \
sed -e "s/^/#define EXAMPLE_targetloc \"/" | \
sed -e "s/$/\"/" > config.hats
patscc -o test_prog main.dats -DATS_MEMALLOC_LIBC
/home/kiwamu/src/c2ats/example/satstree/out/usr/include/x86_64-linux-gnu/sys/cdefs.sats: 55(line=2, offs=1) -- 95(line=2, offs=41): error(0): including the file [/home/kiwamu/src/c2ats/example/satstree/out/usr/include/features.sats] generates the following looping trace:
/home/kiwamu/src/c2ats/example/satstree/out/usr/include/x86_64-linux-gnu/sys/cdefs.sats
/home/kiwamu/src/c2ats/example/satstree/out/usr/include/features.sats
/home/kiwamu/src/c2ats/example/satstree/out/usr/include/stdio.sats
/home/kiwamu/src/c2ats/example/satstree/out/home/kiwamu/src/c2ats/example/satstree/example.sats
/home/kiwamu/src/c2ats/example/satstree/out/home/kiwamu/src/c2ats/example/satstree/example.sats
/home/kiwamu/src/c2ats/example/satstree/main.dats
/home/kiwamu/src/c2ats/example/satstree/main.dats
It seems like we can't escape with #ifndef pattern...
Need capturing include loop and cut sub tree.
And should also inject #include "out/c2ats_prelude.sats" into out/home/kiwamu/src/c2ats/example/satstree/example.sats.
We should create gtk3tree example.
$ pwd
/home/kiwamu/src/c2ats/example/satstree_gtk3
$ make
--snip--
patscc -o test_prog main.dats -DATS_MEMALLOC_LIBC `pkg-config --cflags --libs gtk+-3.0`
/home/kiwamu/src/c2ats/example/satstree_gtk3/out/usr/include/x86_64-linux-gnu/bits/sigaction.sats: 212(line=7, offs=16) -- 237(line=7, offs=41): error(2): the static identifier [type_c2ats___sighandler_t] is unrecognized.
The type is defined at out/usr/include/signal.sats. Why isn't it included?
$ grep -r /signal.sats out
out/usr/include/glib-2.0/glib/gbacktrace.sats:#include "out/usr/include/signal.sats"