Octave Coder __ A code generator and build system that converts Octave to C++

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Octave Coder __ A code generator and build system that converts Octave to C++

Hossein Sajjadi
Dear Octave maintainers,

I have developed an Octave package named "coder" which converts
Octave .m file to ,oct file. All versions of Octave starting from
4.4.0 are supported.

Simple Usage:

    octave2oct('myfunction');

Octave instructions, are translated to the intermediate Coder C++ API.
The intermediate API as its backend uses the  oct c++ API and links
against Octave core libraries. Names and symbols are resolved at
translation time to get rid of symbol table lookup at runtime and
there is no AST traversal so the generated .oct files are supposed to
run faster than the original .m files. Speed-up is usually 3X - 4X
relative to the interpreter.

The package is hosted at https://github.com/shsajjadi/OctaveCoder .

Any advice, feedback, bug report will be appreciated.

Best Regards,

Hossein
(Seyyed Hossein Sajjadi)

Reply | Threaded
Open this post in threaded view
|

Re: Octave Coder __ A code generator and build system that converts Octave to C++

Carlo de Falco-2
Hi,

Thanks for sharing this, sounds like a great project!


> Il giorno 4 giu 2020, alle ore 18:41, Hossein Sajjadi <[hidden email]> ha scritto:
>
> Any advice, feedback, bug report will be appreciated.


I tried to compile the attached very simple function pippo.m
and compilation failed with the following error :

./pippo.cc:2194:53: error: cannot pass non-trivial object of type 'const std::string'
      (aka 'const basic_string<char, char_traits<char>, allocator<char> >') to variadic function; expected type from format string was 'char *' [-Wnon-pod-varargs]
              error("cannot find %s.oct>%s in %s ", file_name, fcn_name, path);
                                 ~~                 ^~~~~~~~~

also, as I am using clang++ the option '-gtoggle' that is hardcoded in all compiler commands is not understood and causes all invocations to the compiler to fail.

HTH,
c.



pippo.m (70 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Octave Coder __ A code generator and build system that converts Octave to C++

Carlo de Falco-2


> Il giorno 4 giu 2020, alle ore 20:16, Carlo De Falco <[hidden email]> ha scritto:
>
> Hi,
>
> Thanks for sharing this, sounds like a great project!
>
>
>> Il giorno 4 giu 2020, alle ore 18:41, Hossein Sajjadi <[hidden email]> ha scritto:
>>
>> Any advice, feedback, bug report will be appreciated.
>
>
> I tried to compile the attached very simple function pippo.m
> and compilation failed with the following error :
>
> ./pippo.cc:2194:53: error: cannot pass non-trivial object of type 'const std::string'
>      (aka 'const basic_string<char, char_traits<char>, allocator<char> >') to variadic function; expected type from format string was 'char *' [-Wnon-pod-varargs]
>              error("cannot find %s.oct>%s in %s ", file_name, fcn_name, path);
>                                 ~~                 ^~~~~~~~~
>
> also, as I am using clang++ the option '-gtoggle' that is hardcoded in all compiler commands is not understood and causes all invocations to the compiler to fail.
>
> HTH,
> c.


I would suggest removing '%s' from this line :

https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2091

and using std::string::c_str () in these lines :

https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2204
https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2228
https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2249
https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2264

c.




Reply | Threaded
Open this post in threaded view
|

Re: Octave Coder __ A code generator and build system that converts Octave to C++

Hossein Sajjadi
Thanks, Carlo
Bugs fixed. versions 4.4.1 , 5.1.1 and 5.2.1 released.

On 6/4/20, Carlo De Falco <[hidden email]> wrote:

>
>
>> Il giorno 4 giu 2020, alle ore 20:16, Carlo De Falco
>> <[hidden email]> ha scritto:
>>
>> Hi,
>>
>> Thanks for sharing this, sounds like a great project!
>>
>>
>>> Il giorno 4 giu 2020, alle ore 18:41, Hossein Sajjadi
>>> <[hidden email]> ha scritto:
>>>
>>> Any advice, feedback, bug report will be appreciated.
>>
>>
>> I tried to compile the attached very simple function pippo.m
>> and compilation failed with the following error :
>>
>> ./pippo.cc:2194:53: error: cannot pass non-trivial object of type 'const
>> std::string'
>>      (aka 'const basic_string<char, char_traits<char>, allocator<char> >')
>> to variadic function; expected type from format string was 'char *'
>> [-Wnon-pod-varargs]
>>              error("cannot find %s.oct>%s in %s ", file_name, fcn_name,
>> path);
>>                                 ~~                 ^~~~~~~~~
>>
>> also, as I am using clang++ the option '-gtoggle' that is hardcoded in all
>> compiler commands is not understood and causes all invocations to the
>> compiler to fail.
>>
>> HTH,
>> c.
>
>
> I would suggest removing '%s' from this line :
>
> https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2091
>
> and using std::string::c_str () in these lines :
>
> https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2204
> https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2228
> https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2249
> https://github.com/shsajjadi/OctaveCoder/blob/dev/src/coder_runtime.cpp#L2264
>
> c.
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Octave Coder __ A code generator and build system that converts Octave to C++

apjanke-floss
In reply to this post by Hossein Sajjadi


On 6/4/20 12:41 PM, Hossein Sajjadi wrote:

> Dear Octave maintainers,
>
> I have developed an Octave package named "coder" which converts
> Octave .m file to ,oct file. All versions of Octave starting from
> 4.4.0 are supported.
>
> Simple Usage:
>
>     octave2oct('myfunction');
>
> Octave instructions, are translated to the intermediate Coder C++ API.
> The intermediate API as its backend uses the  oct c++ API and links
> against Octave core libraries. Names and symbols are resolved at
> translation time to get rid of symbol table lookup at runtime and
> there is no AST traversal so the generated .oct files are supposed to
> run faster than the original .m files. Speed-up is usually 3X - 4X
> relative to the interpreter.
>
> The package is hosted at https://github.com/shsajjadi/OctaveCoder .
>
> Any advice, feedback, bug report will be appreciated.
>
> Best Regards,
>
> Hossein
> (Seyyed Hossein Sajjadi)
>

This is very interesting! I know there are a couple other people on that
list who will find this of interest, too. Thanks for your contribution.

Cheers,
Andrew

Reply | Threaded
Open this post in threaded view
|

Re: Octave Coder __ A code generator and build system that converts Octave to C++

Carlo de Falco-2
In reply to this post by Hossein Sajjadi
Hi,

> Il giorno 4 giu 2020, alle ore 22:46, Hossein Sajjadi <[hidden email]> ha scritto:
>
> Thanks, Carlo
> Bugs fixed. versions 4.4.1 , 5.1.1 and 5.2.1 released.
>

I just created a pull request on GitHub to fix more clang errors and warnings,
but I still see the following warnings you may want to handle :


OctaveCoder/src/code_generator.cpp:448:15: warning: enumeration values 'num_binary_ops'
      and 'unknown_binary_op' not handled in switch [-Wswitch]
      switch (etype)
              ^
OctaveCoder/src/code_generator.cpp:448:15: note: add missing switch cases
      switch (etype)
              ^
OctaveCoder/src/code_generator.cpp:591:15: warning: enumeration values
      'num_compound_binary_ops' and 'unknown_compound_binary_op' not handled in switch [-Wswitch]
      switch (etype)
              ^
OctaveCoder/src/code_generator.cpp:591:15: note: add missing switch cases
      switch (etype)
              ^
OctaveCoder/src/code_generator.cpp:1740:17: warning: 5 enumeration values not handled in
      switch: 'op_not', 'op_uplus', 'op_uminus'... [-Wswitch]
        switch (etype)
                ^
OctaveCoder/src/code_generator.cpp:1740:17: note: add missing switch cases
        switch (etype)
                ^
OctaveCoder/src/code_generator.cpp:1772:17: warning: 4 enumeration values not handled in
      switch: 'op_transpose', 'op_hermitian', 'num_unary_ops'... [-Wswitch]
        switch (etype)
                ^
OctaveCoder/src/code_generator.cpp:1772:17: note: add missing switch cases
        switch (etype)
                ^
OctaveCoder/src/code_generator.cpp:1824:17: warning: enumeration values 'num_assign_ops'
      and 'unknown_assign_op' not handled in switch [-Wswitch]
        switch (etype)
                ^
OctaveCoder/src/code_generator.cpp:1824:17: note: add missing switch cases
        switch (etype)
                ^
5 warnings generated.


and also :

pippo.cc:3775:45: warning: relational comparison result unused [-Wunused-comparison]
              for (octave_idx_type i = k; i < nel, j < nargout_retval; i++)



which comes from line 3785 in "coder_runtime.cpp"


c.



Reply | Threaded
Open this post in threaded view
|

Re: Octave Coder __ A code generator and build system that converts Octave to C++

Hossein Sajjadi
On 6/5/20, Hossein Sajjadi <[hidden email]> wrote:

> Carlo,
> Sorry for late reply. It is my first experience with github.
>
> On 6/5/20, Carlo De Falco <[hidden email]> wrote:
>> Hi,
>>
>>> Il giorno 4 giu 2020, alle ore 22:46, Hossein Sajjadi
>>> <[hidden email]> ha scritto:
>>>
>>> Thanks, Carlo
>>> Bugs fixed. versions 4.4.1 , 5.1.1 and 5.2.1 released.
>>>
>>
>> I just created a pull request on GitHub to fix more clang errors and
>> warnings,
>> but I still see the following warnings you may want to handle :
>>
>>
>> OctaveCoder/src/code_generator.cpp:448:15: warning: enumeration values
>> 'num_binary_ops'
>>       and 'unknown_binary_op' not handled in switch [-Wswitch]
>>       switch (etype)
>>               ^
>> OctaveCoder/src/code_generator.cpp:448:15: note: add missing switch cases
>>       switch (etype)
>>               ^
>> OctaveCoder/src/code_generator.cpp:591:15: warning: enumeration values
>>       'num_compound_binary_ops' and 'unknown_compound_binary_op' not
>> handled
>> in switch [-Wswitch]
>>       switch (etype)
>>               ^
>> OctaveCoder/src/code_generator.cpp:591:15: note: add missing switch cases
>>       switch (etype)
>>               ^
>> OctaveCoder/src/code_generator.cpp:1740:17: warning: 5 enumeration values
>> not handled in
>>       switch: 'op_not', 'op_uplus', 'op_uminus'... [-Wswitch]
>>         switch (etype)
>>                 ^
>> OctaveCoder/src/code_generator.cpp:1740:17: note: add missing switch
>> cases
>>         switch (etype)
>>                 ^
>> OctaveCoder/src/code_generator.cpp:1772:17: warning: 4 enumeration values
>> not handled in
>>       switch: 'op_transpose', 'op_hermitian', 'num_unary_ops'...
>> [-Wswitch]
>>         switch (etype)
>>                 ^
>> OctaveCoder/src/code_generator.cpp:1772:17: note: add missing switch
>> cases
>>         switch (etype)
>>                 ^
>> OctaveCoder/src/code_generator.cpp:1824:17: warning: enumeration values
>> 'num_assign_ops'
>>       and 'unknown_assign_op' not handled in switch [-Wswitch]
>>         switch (etype)
>>                 ^
>> OctaveCoder/src/code_generator.cpp:1824:17: note: add missing switch
>> cases
>>         switch (etype)
>>                 ^
>> 5 warnings generated.
>>
>>
>> and also :
>>
>> pippo.cc:3775:45: warning: relational comparison result unused
>> [-Wunused-comparison]
>>               for (octave_idx_type i = k; i < nel, j < nargout_retval;
>> i++)
>>
>>
>>
>> which comes from line 3785 in "coder_runtime.cpp"
>>
>>
>> c.
>>
>>
>>
>
>
> --
>
> Sincerely,
> Hossein
>


--

Sincerely,
Hossein

Carlo, sorry for late reply.
Thank you for your extended review and bug fixes.
For the error related to -gtoggle I have changed it to -g0. My current
plan is to support all versions of Octave from 4.4.0. I have read some
threads that recommended to push changes in the oldest branch ,here is
branch 4, and merge changes to newer branches. However your changes is
in branch 'dev' . I 'm not sure what should I do.