MCode4GCC -- C/C++ to MCode Generator

Post your working scripts, libraries and tools
User avatar
joedf
Posts: 5328
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

MCode4GCC -- C/C++ to MCode Generator

20 Sep 2014, 21:09

MCode4GCC

MCode4GCC is an MCode generator using the GCC Compiler.
More about MCode here : viewtopic.php?f=7&t=32
Info & downloads here: https://github.com/joedf/MCode4GCC

Image

Questions?
Don't be shy to post your questions. Just ask away!

Credits
Special thanks to IsNull, fincs, Laszlo, SKAN, Bentschi and kon
Written by joedf ( joedf@ahkscript.org )
Released under the [MIT License]( http://opensource.org/licenses/MIT )

Information and Downloads here : https://github.com/joedf/MCode4GCC
Elduke

Re: MCode4GCC -- C/C++ to MCode Generator

24 Oct 2014, 13:49

dumb question... is visual c++ needed?
kon
Posts: 1661
Joined: 29 Sep 2013, 17:11

Re: MCode4GCC -- C/C++ to MCode Generator

24 Oct 2014, 14:07

Elduke wrote:dumb question... is visual c++ needed?

Nope! :D
GCC is an open source compiler. You just need GCC and an editor of your choosing.
Setting Up GCC on this script's GitHub page lists some of the recommended distributions.
User avatar
fincs
Posts: 493
Joined: 30 Sep 2013, 14:17
GitHub: fincs
Location: Seville, Spain
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

24 Oct 2014, 15:36

I use TDM-GCC. The 'normal' one just loves to link in dependencies to all sorts of hefty runtime DLLs.
fincs
Windows 10 x64 Build 14393 / AutoHotkey v1.1.24.04
Get SciTE4AutoHotkey v3.0.06.01 - [My project list]
User avatar
Relayer
Posts: 94
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: MCode4GCC -- C/C++ to MCode Generator

24 Oct 2014, 15:42

Is there a repository of MCode functions with docs? I'd be interested in previous work since I'm not that proficient at writing my own C code.

Relayer
Sam_
Posts: 31
Joined: 20 Mar 2014, 20:24

Re: MCode4GCC -- C/C++ to MCode Generator

14 Nov 2014, 20:24

I'm not a c++ programmer, but there are a couple MCode functions from the old forum that I need x64 version for, so I decided to give this a try. I think I got everything set up correctly as I successfully got the test TheAnswerToEverything() function to compile to MCode. I added it as a function in my script and it works. Now I try compiling the Bin2Hex and Hex2Bin functions, and I am getting errors like:
SOURCEFILE:1:14: error: unknown type name 'UInt8'
void Bin2Hex(UInt8 *hex, UInt8 *bin, Int32 len) { // in hex room for 2*len+1 bytes
^
SOURCEFILE:1:26: error: unknown type name 'UInt8'
void Bin2Hex(UInt8 *hex, UInt8 *bin, Int32 len) { // in hex room for 2*len+1 bytes
^
SOURCEFILE:1:38: error: unknown type name 'Int32'
void Bin2Hex(UInt8 *hex, UInt8 *bin, Int32 len) { // in hex room for 2*len+1 bytes
^

What is happening here? Do I need to adjust the jargon of the data types or something?

For convenience, these are the two functions I need MCode for:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
joedf
Posts: 5328
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

15 Nov 2014, 11:28

Yup
Sam_
Posts: 31
Joined: 20 Mar 2014, 20:24

Re: MCode4GCC -- C/C++ to MCode Generator

18 Nov 2014, 04:37

Thank you both! I have now gotten both functions to compile nicely, and everything works great in the ANSI build of AHK_L, less so in the Unicode builds. Here is my original test script:

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus


Notice that it works as expected in the ANSI build of AHK_L, but the hex data is not displayed properly in Unicode builds. This can be remedied by:

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

Bin2Hex(ByRef hex,addr,len){
VarSetCapacity(hex,(2*len+1)*(A_IsUnicode?2:1))
Global _Bin2Hex
DllCall(_Bin2Hex,"UInt",&hex,"UInt",addr,"UInt",len,"CDECL")
If (A_IsUnicode=1)
hex:=StrGet(&hex,len*(A_IsUnicode?2:1),"cp0") ; Without this, it only works properly in the AHK_L ANSI build
Return VarSetCapacity(hex,-1)//2
}

But now the hex data is not properly converted back to binary (in Unicode builds of AHK_L) and so is not written back to the file properly. My problem is I can't figure out how to undo the codepage manipulation:

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

Hex2Bin(ByRef bin,ByRef hex){
VarSetCapacity(bin,0)
;~ VarSetCapacity(bin,((StrLen(hex)+1)//2)/(A_IsUnicode?2:1))
VarSetCapacity(bin,(StrLen(hex)+1)//2)
If (A_IsUnicode=1){
; Some way to undo the Unicode compatability stuff
}
Global _Hex2Bin
DllCall(_Hex2Bin,"UInt",&bin,"UInt",&hex,"CDECL")
Return (StrLen(hex)+1)//2
}

I apologize if this is straying too far off topic, but if anyone can help me out, I'd really appreciate it!
User avatar
nnnik
Posts: 1803
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode4GCC -- C/C++ to MCode Generator

21 Nov 2014, 02:43

TDM-GCC wrote:>>>>> USAGE NOTES

*** 32-bit or 64-bit compilation ***

In this edition of TDM-GCC, you can use "-m32" and "-m64" to control whether
32-bit or 64-bit binaries are generated. By default (if neither -m32 nor -m64 is
specified), 64-bit binaries will be generated. In a 64-bit binary, all pointer
math is 64-bit by default, and the built-in "size_t" and "ptrdiff_t" types are
64 bits in size (some other types are larger also). Additionally, the following
preprocessor definitions will be in effect:
* #define _WIN64 1 (also WIN64, __WIN64, and __WIN64__)
* #define __MINGW64__ 1
* #define __x86_64 1 (also __x86_64__)
* #define __amd64 1 (also __amd64__)
Be sure to use "-m32" or "-m64" at both the compile stage and the link stage.

Just saying :)
I am not afraid of many things. But I do fear fear.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: lordsephirote, Randy31416 and 16 guests