We should take this thread to the developer section of the forum ?
Well. I just got back and here is an update.
I have a added the first pass approach the converter and I have added a handler to process CPP different from .H ( this is to improve performance and make the code easier to maintain).
The new converter now creates the output shown below!
I will explain. The coverter is going thru and finding (at the moment) just the BOOL method(s). When it find a BOOL method it processes the BOOL method counting "{" or "}". This counting like this finds the end of the method. It then marks the code as PRESERVED. If line is PRESERVED then on later processes does not reprocess the line again.
So, as you can see the raw C code is now shown. So, what is the ;?F3L21S0? - these are File number, Line number and Subroutine number, We will need this metadata later when we start to look for calls to subroutines. Metadata can be used and then removed later.
Already, you can see the structure of the code, some the logic and it you see the core C code. And, think of two copies of the C code - for each line there is 1) A copy that is changed as we process, and,2) a copy that has the original line plus the metadata (the master code).
Current command line - now includes CPP file. The order of the files on the command line is not important.
I have refactored the converter to now handle all type of C methods, and, to output to the command/terminal window and output the 'converted' code to OUTPUT.GCB
Command line is: cls&gawk -f ctogcb.awk MAX30100.h MAX30100_Registers.h MAX30100.cpp
OUTPUT.GCB as all the constants and code as show below.
So, now to the interesting bit to start processing all the code. The approach will be again very similar to GCBASIC compiler. Find and process things in order to convert the code.
A progress update. The latest attachment is now generating GCB code for specific case. I have added the processing for C IF staements.
The IF handler. Support single and multiple lines IFs an IF-ELSE again with single and multiple lines statements.
The processing now has a reusable function called findnextmatchingRbraces() where you get back the pointer to the next matched brace. Which essentially means the converter knows where to place the GCB code.
Examples follow but this new converter code means that you now take a specific function and work in on independently - Compile Wire. commands for instance. I will do WHILE and FOR-NEXT next.
The converter now outputs messages to the terminal and an OUTPUT.GCB file and UNPROCESSED.CPP file. They contain the coverted file and stuff the converter cannot handle.
To GCB Code - ignore the Original coding as this will be removed later.
Note. To maintain line numbering that in some cases the multiline GCB seperator is needed.
This is an example of conversion. The only change to make this work would be to change UINT8_T BASEADDRESS, UINT8_T *BUFFER, UINT8_T LENGTH to BASEADDRESS, BUFFER() , LENGTH the parameters,
Whilst no converter will be perfect this will convert almost all the code. There will be many conditions to be added or sorted but not to shabby for a few hours.
A program using the converted code. I have created a test program (actually this is the first I have every tried I was just reviewing in the editor prior to this test).
It compiles. After adding HWI2C and the required variables and constants.
The latest CtoGCBASIC converter. It is pretty good.
This version has improvements to the quality of the conversion. I have rewritten the pattern matching routines to improve the ability to recognise all the code.
The process output two files - OUTFILE.GCB and UNPROCESSED.GCB - the terminal window will issue warnings specifically to I2C handling with recommendations on resolution in the OUTFILE.GCB
I have put some code through the converter and Angel is loading the converter onto the GCBASIC website so you can drag files in, and, get them converted from C to GCBASIC.
Insights:
There are commands and variables that are not permitted by GCBASIC compiler and/or MPASM. This is important. C naming permits the use of sub routines like Shutdown() and variables like Data or Address. All of these are reserved words. There will be more like this. So, the converter will flag these and convert the code. The user will have to resolve as the converter would be guessing to change the names of any object.
Floats are permitted in C. The converter will comment out all code within a float method. The user will have to resolve using factorization.
C creates and uses local variables. There will be a need to move array definitions from the subs and/or functions to main user program.
The files created are all in upper case and the indents are not corrected. The user will have to resolve.
The converter uses GCBASIC multiline coding styles ( for specific conversions ). The user will have to adapt the converted code to move code to a single - only needed to make it look nice. The is no function difference either way.
When Angel creates the converter Web page. This thread will cease. And, any issue should reported via the GCBASIC issue tracker.
Meanwhile... it is very cool to see it work!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This was 99% completly converted. Minor editing needed in a for-next statement! Clearly the I2C commands would need updating but this would be a great start for anyone.
Converted a few .ino to GCB lately,
Arduino coders - to set/clear a register bit, tend to like using shifting a bit into position using the register bit name as a constant eg.[mega328] ADCSRB = (0 << ACME) where ACME is bit 6
GCbasic... ADCSRB.6 = 0
So need to check the bitname position in mega328.dat file. "ACME,ADCSRB,6"
As the chip-name is not defined in .ino code like GCbasic maybe some method of input the chip-name for convert .ino -> .gcb might be helpful.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We should take this thread to the developer section of the forum ?
Well. I just got back and here is an update.
I have a added the first pass approach the converter and I have added a handler to process CPP different from .H ( this is to improve performance and make the code easier to maintain).
The new converter now creates the output shown below!
I will explain. The coverter is going thru and finding (at the moment) just the BOOL method(s). When it find a BOOL method it processes the BOOL method counting "{" or "}". This counting like this finds the end of the method. It then marks the code as PRESERVED. If line is PRESERVED then on later processes does not reprocess the line again.
So, as you can see the raw C code is now shown. So, what is the ;?F3L21S0? - these are File number, Line number and Subroutine number, We will need this metadata later when we start to look for calls to subroutines. Metadata can be used and then removed later.
Already, you can see the structure of the code, some the logic and it you see the core C code. And, think of two copies of the C code - for each line there is 1) A copy that is changed as we process, and,2) a copy that has the original line plus the metadata (the master code).
Current command line - now includes CPP file. The order of the files on the command line is not important.
gawk -f ctogcb.awk max30100.h MAX30100_Registers.h max30100.cpp
Enjoy
Why use the funny metaadata ? This is the same method as the GCBASIC compiler uses and that works very nicely.
Why use PRESERVED ? This is the same method as the GCBASIC compiler uses and that works very nicely.
Last edit: Anobium 2023-01-13
I have refactored the converter to now handle all type of C methods, and, to output to the command/terminal window and output the 'converted' code to OUTPUT.GCB
Command line is: cls&gawk -f ctogcb.awk MAX30100.h MAX30100_Registers.h MAX30100.cpp
OUTPUT.GCB as all the constants and code as show below.
Terminal now shows information.
So, now to the interesting bit to start processing all the code. The approach will be again very similar to GCBASIC compiler. Find and process things in order to convert the code.
Easy
@mmotte
A progress update. The latest attachment is now generating GCB code for specific case. I have added the processing for C IF staements.
The IF handler. Support single and multiple lines IFs an IF-ELSE again with single and multiple lines statements.
The processing now has a reusable function called
findnextmatchingRbraces()
where you get back the pointer to the next matched brace. Which essentially means the converter knows where to place the GCB code.Examples follow but this new converter code means that you now take a specific function and work in on independently - Compile Wire. commands for instance. I will do WHILE and FOR-NEXT next.
The converter now outputs messages to the terminal and an OUTPUT.GCB file and UNPROCESSED.CPP file. They contain the coverted file and stuff the converter cannot handle.
Enjoy
Example 1
To GCB Code - ignore the Original coding as this will be removed later.
Note. To maintain line numbering that in some cases the multiline GCB seperator is needed.
Example 2
To GCB Code
Example 3
To GCB Code. The READOUTSBUFFER.ISEMPTY() and the pointers will be resolved later as the convertor is developed.
Example 4
To GCB Code. The READOUTSBUFFER.ISEMPTY() and the pointers will be resolved later as the convertor is developed.
Same commandline: cls&gawk -f ctogcb.awk MAX30100.h MAX30100_Registers.h MAX30100.cpp
See AWK attached.
Just added C While() functional syntax. Now the basic conversion routines are working - it is a lot faster.
to GCB follows. This uses GCBASIC line concat to maintain the lines of code.
Last edit: Anobium 2023-01-16
Just updated to add I2C, variable management and top and tail methods.
Only parameters to complete.
Examples:
Converted to ( note the paramteters are not converted.
This is an example of conversion. The only change to make this work would be to change
UINT8_T BASEADDRESS, UINT8_T *BUFFER, UINT8_T LENGTH
toBASEADDRESS, BUFFER() , LENGTH
the parameters,Whilst no converter will be perfect this will convert almost all the code. There will be many conditions to be added or sorted but not to shabby for a few hours.
Enjoy
A program using the converted code. I have created a test program (actually this is the first I have every tried I was just reviewing in the editor prior to this test).
It compiles. After adding HWI2C and the required variables and constants.
:=)
The latest CtoGCBASIC converter. It is pretty good.
This version has improvements to the quality of the conversion. I have rewritten the pattern matching routines to improve the ability to recognise all the code.
The process output two files - OUTFILE.GCB and UNPROCESSED.GCB - the terminal window will issue warnings specifically to I2C handling with recommendations on resolution in the OUTFILE.GCB
Example of code:
C source
GCBASIC
The code is acceptable. As this is very close to a full conversion.
The outstanding change is to improve the parameters in the methode definitions but this can wait till next week.
Enjoy
The terminal looks like this ... not to confusing.
Last edit: Anobium 2023-01-19
I have put some code through the converter and Angel is loading the converter onto the GCBASIC website so you can drag files in, and, get them converted from C to GCBASIC.
Insights:
When Angel creates the converter Web page. This thread will cease. And, any issue should reported via the GCBASIC issue tracker.
Meanwhile... it is very cool to see it work!!
Lots of hard work and progress. Thanks Evan.
If only... I had done this a few years ago...
An example SDDD1306.CPP from GitHub.
This was 99% completly converted. Minor editing needed in a for-next statement! Clearly the I2C commands would need updating but this would be a great start for anyone.
I impressed myself.
Evan
Last edit: Anobium 2023-01-22
Converted a few .ino to GCB lately,
Arduino coders - to set/clear a register bit, tend to like using shifting a bit into position using the register bit name as a constant eg.[mega328] ADCSRB = (0 << ACME) where ACME is bit 6
GCbasic... ADCSRB.6 = 0
So need to check the bitname position in mega328.dat file. "ACME,ADCSRB,6"
As the chip-name is not defined in .ino code like GCbasic maybe some method of input the chip-name for convert .ino -> .gcb might be helpful.
Good idea. The script will be on the website soon. One of the key parameters will have to be the chip name - you raise a great point.