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
How about integrating with Alien::TinyCC ? #1
Comments
@tsee, you and I are thinking along the same lines. :-) I've gotten some basics started, including a potentially over-engineered package system to build reusable modules. For example, I can call C-compiled functions from Perl, and I've added a simple data structure system. But I know I could do a lot better, especially with calling compiled functions from Perl. Shall we try to merge XS::TCC and C::TinyCompiler? David |
Hi David, On 08/21/2013 05:58 PM, David Mertens wrote:
tl;dr: I'm open to that, with some caveats. First a quick disclosure: XS::TCC has been on github for a while. It was Fundamentally, the two modules work a tad differently. You rely on "FFI" On top of that, there is a very curious effect that is specific to the To wit, some arbitrary n^2 thing I used for testing showed TCC to beat The way out for many typemaps is to include functions in the actual You've had a some really good ideas that I'd love to see in a merged Did you solve the debugging-this-inlined-C-code-is-a-nightmare-problem, This was about where I left off and started being distracted by my PLua This in turn has most recently been pushed down in priority when Mattia The last bit is important only because I currently can't help much with Either way I've given you commit/push access to the XS::TCC repository Best regards, [1] https://github.com/tsee/p5-Plua |
BTW, calling this kind of setup a "JIT" is a bit misleading, IMO. :) |
Also, I'm by all means open to using Alien::TCC. Just not in a position to do the work. See also @tokuhirom's tickets about the TCC compilation/compatibility with OSX. |
Lots to reply to. I know what you mean about things sitting around and not getting pushed out to CPAN. I've been working on C::TinyCompiler in spurts for about two years. I polished it and pushed it out only recently in reply to an email on the tincc-devel mailing list. First the easy one: line numbering. I wrote a function called "line_number" that generates a "#line" directive for the user: http://search.cpan.org/~dcmertens/C-TinyCompiler-0.02/lib/C/TinyCompiler.pm#line_number. (I apologize for giving a link to a specific version of the module; I'd use metacpan, but it's displaying my README.pod instead of my module's pod, for some irritating reason.) This was based on some work I did with PDL::PP, and the lack of line reporting in that module's output. I could do better by adding another API function for appending code to the Body section which gets the line number from caller(). As for the meatier question: I think we really are mostly aiming at the same mark, but we have an important difference in our approach. The key difference is that I explicitly did not want to require the Perl API headers in all compilation contexts. I want to give the minimal amount of code to tcc when it comes time to compile, and I want to compile as much as possible at build time, with an optimized compiler. Two motivating examples: (1) using the GSL and (2) wishing to construct a C function for a C callback (i.e. not a Perl function reference callback wrapper, a real C function). For GSL, I don't want tcc to spend time reading the C sources from disk and building unoptimized machine code when I already have an optimized .so or .dll. And if somebody is trying to write a simple C function callback, they don't need the Perl headers, so why force them? These examples, and the goal for minimal C code in the context, led me to develop the package system, which (among other things) aims to make it easy to add pre-compiled functions to a compilation unit. In fact, I really don't care much about data munging because, as you said, I would rather folks use Convert::Binary::C for those purposes. I suspect you got that impression after reading over the poorly internally documented C::TinyCompiler::Callable. That brings us to FFI. Although at one stage in its development I decided to fall back on FFI::Raw for invoking the C functions, I decided that FFI::Raw's interface was too closed for my needs to be useful. For example, I had no simple way to send PDL data to a function with an FFI::Raw interface, even though I could get a reference to the SV* that held the PDL data. I also didn't like that FFI::Raw depended on an external library, but didn't provide for it. For these reasons, I wrote my own function wrapper code. It's slow and kludgey, and it really should use typemaps, but it works for now with basic types and pointers. The flexibility with the pointers is really the big win. Still, my hope is to eventually replace it with a bona fide xsub wrapper, and to utilize the institutional knowledge already wrapped in known typemaps. Fortunately, my little ffi is just a "C::TinyCompiler::package," with a simple enough API, and it should be possible to completely alter the internals to use xsubs once I figure out how to distill Perl's xsub signature, and use the typemap code. Originally I had hoped to provide a direct interface to libtcc. However, I quickly discovered with a few tests that two uncompiled compiler contexts cannot coexist in tcc: it uses internal globals during the compilation stage. For this reason, I changed my approach. I don't actually create a TCCState until the Perl-side "compile" method is invoked. All of my Perl-side compiler object methods simply add data to the blessed hash. When it comes time to compile, then I do any source munging, create the TCCState, compile, and relocate. This way, you can have multiple compilers floating around without clashing. The only potential pitfall now would be due to simultaneous compilation in a multithreaded environment, or a package that stupidly decides to compile something during its preprocess stage. As to the topic of this ticket, I'll work on a branch to use Alien::TinyCC and submit that as a pull request in a bit. I'll keep it as a pull request, though, so that you and anybody else interested can independently clone the work and test it before it gets merged. |
Indeed a big reply 👍 I am watching this project more closely. |
By the way, it may be possible to completely avoid any Perl-side function parsing. See http://lists.nongnu.org/archive/html/tinycc-devel/2013-08/msg00019.html, and the follow-up with the actual patch at http://lists.nongnu.org/archive/html/tinycc-devel/2013-08/msg00020.html |
XS::TCC 0.03 now relies on Alien::TinyCC! Cheers and thanks for the help and encouragement! Closing this ticket since it pertains to using the Alien module specifically. |
I just realized the -fPIC stuff is only in git, so I'll push out a non-dev David On Thu, Aug 29, 2013 at 1:46 PM, Steffen Müller notifications@github.comwrote:
"Debugging is twice as hard as writing the code in the first place. |
Hi
tcc source is bundled in XS::TCC.
There are another tcc-perl binding modules ( Alien::TinyCC, C::TinyCompiler )
Now Alien::TinyCC can also be built on Windows. ( run4flat/Alien-TinyCC#1 )
How about integrating & building with Alien::TinyCC like C::TinyCompiler instead of bundling tcc ?
The text was updated successfully, but these errors were encountered: