First of all, this is not your standard "I want to compile Java code to machine code" question.
I'm working on a compiler written in Java, that will translate a certain language (in my case: Brainfuck) to x86 Assembly, after that I'm currently planning to use NASM and GCC to produce machine code.
Seeing as the HotSpot JVM can compile Java bytecode to machine code, I assume there is some mechanism available to compile source code of type A to machine code.
Is there any way to use this in a compiler written in Java? My main goal is to explore the possibility of writing a compiler in Java without relying on external programs, for example GCC and NASM, being available on the path. I do need a C Compiler because I'm linking with the cstdlib as I'm using those functions in my x86 Assembly code.
To clarify, I'm doing the following currently:
- Write x86 Assembly to a
bf.asm
file. - Transform Assembly to Object code with
nasm -f win32 bf.asm
. - Link the Object code with Windows OS and cstdlib libraries with
gcc -o bf bf.obj
.
I'm searching for the possibilities of replacing the need of using nasm
and gcc
in steps 2 and 3 and instead do those with Java code.