Creating EXE files in VC++

Programming, for all ages and all languages.
Post Reply
R Karthick

Creating EXE files in VC++

Post by R Karthick »

Hi there,

I would like to develop a compiler in win32 environment using VC++. Is there any way, i'll b able to generate executable code in VC++. Like i would want my program to create exe files on the fly, like vc++ or vb or any other programming language.

thnx in advance,
R Karthick
Schol-R-LEA

Re:Creating EXE files in VC++

Post by Schol-R-LEA »

Of course. Visual C++ is a superset of C++, which is a superset of C; and C has been used to write a large number of compilers over the years, including the VC++ compiler. QED.

Actually, it should be possible to write a compiler, at least a simple one, in any language that can write binary data to a file (or something that can be readily converted to it, such as the old Intel HEX format). Compilers and assemblers have been written in COBOL, Fortran, Pascal, Prolog, VB, and, in one truly perverse case (the original implementation of Orthogonal), INTERCAL. While writing one that also handles linking (or which doesn't need a linker, i.e., does not allow external code references) is harder, it is not infeasible.

However, I would be interested in knowing what the application is. Is the compiler itself the final goal, or is it part of a larger program? If the latter, why wouldn't an interpreter (which generally speaking is far easier to write and debug) do as well? Do you intend to write it portable C++, or do you need to use VC++ specific extensions? Do you mean to write a retargetable code generator, and if so, would it make sense to target a simpler CPU or p-machine (say, the JVM) first before trying to generate x86 code? What kind of language do you mean to implement? Or is the goal something else entirely (automatic program generation, genetic algorithms, etc.)?
Tim

Re:Creating EXE files in VC++

Post by Tim »

I think I just answered your question in comp.os.ms-windows.programmer.win32 :).

Anyway, here's my response:
I recommend that you write your compiler to emit assembly code files. You can then assemble them using an assembler (e.g. NASM or Microsoft MASM) to create .OBJ files, which you can link with a linker. Later, you can start emitting .OBJ files directly by emitting machine code instead of text assembly code.
Post Reply