octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implementing loadlibrary, calllib, etc.


From: John Swensen
Subject: Re: Implementing loadlibrary, calllib, etc.
Date: Wed, 24 Mar 2010 10:42:54 -0400

On Mar 24, 2010, at 3:40 AM, Michael Goffioul wrote:

> On Wed, Mar 24, 2010 at 2:46 AM, John Swensen <address@hidden> wrote:
>> I recently had a colleague who used the Matlab loadlibrary, calllib, etc. 
>> functions for accessing stepper motor controller (rather than writing a MEX 
>> function).  I started looking to see if this was available in Octave, as it 
>> seems quite useful, and found that it is not implemented.  I then started 
>> searching for a way of building dynamic function argument lists in C/C++, so 
>> one could dlopen a shared library, parse a header file for function names 
>> with corresponding return type and parameters, and then calling into the 
>> shared library from Octave.
> 
> Good stuff. I have done the same a few years ago for ECL (Lisp 
> Implementation),
> however I didn't actually use FFCALL, because of license mismatch. However
> in this case, I guess using FFCALL is the right way to go.
> 
>> So now it seems that I should be able to do this sort of thing, but lack one 
>> critical skill: regular expressions.  I think I could come up with a very 
>> inelegant way of parsing a header file to extract function names, return 
>> types, and parameters types, but would be open to some help from one of 
>> those regular expression wizards out there in this part of the process.  
>> Once that is complete, I think I can implement the loadlibrary, callib, etc. 
>> quite accurately.  (I suppose I could also take the time to learn regular 
>> expressions well, but that might take more time than I have right now).
> 
> Just wondering if you couldn't use a lex/yacc based parser instead.
> I'm pretty sure you can easily find existing C/C++ syntax files out there, 
> such
> that you'd only have to implement the right hooks, and not worry about
> the C/C++ syntax.
> 
> Michael.

I ended up finding a wrapper around the GCC parser that parses a header or 
source file into XML, intuitively called gcc-xml.  This will be the perfect way 
of doing things.  It supports GCC, VisualC++, Borland, Intel, and SGI, so I 
think it should work for the most used platforms.  The XML nature of the output 
also makes it very each to traverse the file and determine the parameter and 
return types, datatypes in structures, following typedefs back to what they 
call a 'FundamentalType', etc.  Then FFCALL should make it easy to implement 
the calling procedures.

I plan on implementing just the simple case of scalar variables, then moving on 
to arrays/pointers, then working on structures.

John


reply via email to

[Prev in Thread] Current Thread [Next in Thread]