kerneis / cpc Goto Github PK
View Code? Open in Web Editor NEWContinuation Passing C
Home Page: http://www.pps.univ-paris-diderot.fr/~kerneis/software/cpc
License: Other
Continuation Passing C
Home Page: http://www.pps.univ-paris-diderot.fr/~kerneis/software/cpc
License: Other
extern cps f(int x);
…
f(1, 2, 3);
…
This will raise an ocaml exception (Invalid argument ("List.map2")), instead of telling us why, ie. : "invalid number of argument passing to f, line …"
Using the sample file, I get the error:
Error: coroutine-cpc.c:10: wrong number of arguments in function call: *(s->f)
Fatal error: exception Errormsg.Error
I think this is due to the assertion at line 1839 in src/ext/cpc.ml failing, however I was unable to debug it further. Hopefully this is a pretty minimal testcase.
It stops at
/tmp/cpc-0.9.1/bin/cpc.native --out /tmp/cil-VkoZo7Zq.cil.c --warnall /tmp/cil-1o8J_C5l.i
where the program never finishes (and use 100% CPU).
This happens both on the git and the released version.
CC x86_64-softmmu/target-i386/translate.o
/home/cs648/qemu/tcg/tcg-op.h:2165: Warning: Calling function __builtin_unreachable without prototype.
I'm not sure if it's worth including the semantics of __builtin_unreachable(), but it should be added to the builtin function list at the least.
No error are raised when a value is returned in a cpc_spawn (like "return 0;"), but the program will fail.
I don't have check if spawning a cps function returning a value also fails.
block/vmdk.c and block/qcow.c both define a static function get_cluster_offset. CPC generates a helper function __get_cluster_offset_found for both functions, but the definition of this function in both files is not static. This leads to an error that it is defined twice.
CPC runtime has its own cpc_condvar, so it should have CPC-specific longjmp as well.
Desired use case: replace broken Asincify in EmScripten. It's stated that:
ASYNCIFY has a bad worst-case of large code size: If it needs to modify many methods, it can grow code size very significantly (even 10x more was seen).
I don't understand what's wrong with it, but CPC is not growing code size that much, is it?
A good test case would be to replace emterpreter in em-dosbox. Currently most of dosbox code is being compiled as usual, but 40 functions are whitelisted to be executed on emterpreter. I believe, CPC would do better than emterpreter.
For this to work best, CPC should be able to accept blacklists or whitelists like emcc and not require altering of source code. No need to put "cpc" marks.
While working on QEMU I've noticed a problematic interaction between GCC builtins and CPC.
I think the problem lies with CIL rather than CPC. GCC builtins have no prototypes, so CIL inserts a default prototype. GCC then sees the prototype in the source file and decides this means the builtin function shouldn't be used.
Unfortunately I'm not sure what the best solution to this is. I don't know if GCC's behaviour is very standard compliant.
A minimal example (__atomic_thread_fence is a GCC builtin used in QEMU):
http://codepad.org/lDgazDSD
I cannot compile a cpc code with libev (with cpc_runtime.o, it works).
Here is the code :
$ cat toto.cpc
#include <cpc/cpc_runtime.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char **argv)
{
cpc_spawn {
printf("toto\n");
}
cpc_main_loop();
}
And the compiling result :
$ cpc toto.cpc -I cpc -lcpc -pthread
gcc -D_GNUCC -E -I cpc -pthread -DCIL=1 -x c toto.cpc -o /tmp/cil-F0cPvMyf.i
/home/offline/programmation/cpc/obj/cpc.asm.exe --out /tmp/cil-ZdI8fJM3.cil.c /tmp/cil-F0cPvMyf.i
toto.cpc:11: Warning: Body of function main falls-through. Adding a return statement
gcc -D_GNUCC -E -I cpc -pthread /tmp/cil-ZdI8fJM3.cil.c -o /tmp/cil-tLwj1G8h.cil.i
gcc -D_GNUCC -c -I cpc -pthread -pthread -o /tmp/cil-LT9VhhkX.o /tmp/cil-tLwj1G8h.cil.i
gcc -D_GNUCC -o a.out -I cpc -pthread -pthread /tmp/cil-LT9VhhkX.o -lcpc -pthread
/usr/local/lib/libcpc.a(cpc_libev.o): In function `periodic_recalc':
/home/offline/programmation/cpc/runtime/libev/ev.c:2218: undefined reference to `ceil'
/home/offline/programmation/cpc/runtime/libev/ev.c:2218: undefined reference to `ceil'
/home/offline/programmation/cpc/runtime/libev/ev.c:2218: undefined reference to `ceil'
collect2: error: ld returned 1 exit status
static assignment is bugged.
The following code will produce:
file.cpc:48:3: error: 'bugged_pointer___0' undeclared (first use in this function)
static void *bugged_pointer;
cps void*
get_pointer(void)
{
return NULL;
}
cps void
big_bug(void)
{
bugged_pointer = get_pointer();
}
int
main(int argc, char **argv)
{
cpc_spawn big_bug();
cpc_main_loop();
return 0;
}
There is a missing dependency. I'm on debian with the usual packages.
/usr/bin/ocamlopt.opt -c -I src/ext -I ocamlutil -I src -I src/frontc -I src/ext/pta -o src/ext/blockinggraph.cmx src/ext/blockinggraph.ml
File "src/ext/blockinggraph.ml", line 121, characters 2-14:
Error: Unbound value Util.memoize
Dead code may lead to that kind of Warning :
dead-code.cpc:3: Warning: Body of function ret falls-through. Adding a return statement
Example of code :
/* dead-code.cpc */
int main()
{
do {
return 0;
} while(0);
/* dead-code : adding "return 0;" avoid the warning. */
}
(checked on Windows -- cygwin)
Compilation of the "windows-aio" branch of cpc fail under cygwin, due to an unrecognize -g option for flexlink. A similar problem appeared for CIL:
http://www.mail-archive.com/[email protected]/msg00383.html
Remark than now, ocamlutil/Makefile.ocaml doesn't exists anymore in the CIL repository, but still exists in the CPC repository.
Here are the log of the failed compilation of CPC:
http://pastebin.com/YtHpRnUd
and the successful one of CIL:
http://pastebin.com/mPcbLxW4
/home/cs648/qemu/tcg/tcg.c:1642: Warning: Body of function tcg_reg_alloc falls-through. Adding a return statement
gcc -D_GNUCC -E -I/home/cs648/qemu/tcg -I/home/cs648/qemu/tcg/i386 -I/home/cs648/qemu/linux-headers -I/home/cs648/qemu/bin/current/linux-headers -I. -I/home/cs648/qemu -I/home/cs648/qemu/include -I/home/cs648/qemu/tcg -Itcg -DPIE -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -U__SSE2__ -w -Dcoroutine_fn=attribute((cps)) -Dnocps=attribute((nocps)) -I/usr/include/p11-kit-1 -I/usr/include/libpng12 -I/usr/include/pixman-1 -I../linux-headers -I.. -I/home/cs648/qemu/target-i386 -DNEED_CPU_H -I/home/cs648/qemu/include -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -O2 -D_FORTIFY_SOURCE=2 -g ./tcg.cil.c -o ./tcg.cil.i
gcc -D_GNUCC -c -I/home/cs648/qemu/tcg -I/home/cs648/qemu/tcg/i386 -I/home/cs648/qemu/linux-headers -I/home/cs648/qemu/bin/current/linux-headers -I. -I/home/cs648/qemu -I/home/cs648/qemu/include -I/home/cs648/qemu/tcg -Itcg -DPIE -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -U__SSE2__ -w -Dcoroutine_fn=attribute((cps)) -Dnocps=attribute((nocps)) -I/usr/include/p11-kit-1 -I/usr/include/libpng12 -I/usr/include/pixman-1 -I../linux-headers -I.. -I/home/cs648/qemu/target-i386 -DNEED_CPU_H -I/home/cs648/qemu/include -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -O2 -D_FORTIFY_SOURCE=2 -g -Werror -fPIE -m64 -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -w -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-all -pthread -O2 -g -o tcg/tcg.o ./tcg.cil.i
/home/cs648/qemu/tcg/tcg.c:2547:61: error: ‘img’ undeclared here (not in a function)
.e_ident[EI_MAG2] = ELFMAG2,
^
make: *** [tcg/tcg.o] Error 1
make: Leaving directory `/home/cs648/qemu/bin/convert-block/x86_64-softmmu'
tcg.c: http://codepad.org/u5PyyVjO
tcg.i: http://codepad.org/vS3gR45p
tcg.cil.c: http://codepad.org/OaUDEJkp
tcg.cil.i: http://codepad.org/QFJXikz6
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.