14 Apr 18:27
port of jolt-burg
From: John Leuner <jewel@...>
Subject: port of jolt-burg
Newsgroups: gmane.comp.lang.smalltalk.fonc
Date: 2008-04-14 16:30:41 GMT
Subject: port of jolt-burg
Newsgroups: gmane.comp.lang.smalltalk.fonc
Date: 2008-04-14 16:30:41 GMT
I've been working on an experimental port of jolt-burg. The main difference is that my implementation language is Common Lisp and that my compiler targets relocatable ELF object files.
Currently I have a compiler that can read sexp input, eg:
(define |main| (lambda ()
((call-c |dlsym| 0 "puts") "hello, dynamic world!")))
and then compile it down to a tree of blocks and instruction objects (see instruction.lisp or Instruction.st) BLOCK(--- NIL ---) &n bsp; | | 0(--- VOID BLOCK --- 369 &nbs p; | | | | | 0(+++ REG CALLI4 --- &n bsp; | | | | | | 0(+++ REG CNSTP4 --- reloc ---) & nbsp; | | | | | | 0(+++ REG CNSTI4 --- 0) &nb sp; | | | | | | 0(+++ REG CNSTP4 --- reloc ---)) | | | | | 0(+++ REG CNSTP4 --- reloc ---)) &n bsp; | | 0(--- VOID BLOCK --- 369 &nbs p; | | | | | 0(+++ REG CALLI4 EBX &n bsp; | | | | | | 0(+++ REG CNSTP4 EBX reloc ---) & nbsp; | | | | | | 0(+++ REG CNSTI4 EAX 0) &nb sp; | | | | | | 0(+++ REG CNSTP4 ECX reloc ---)) | | | | | 0(+++ REG CNSTP4 EAX reloc ---))
This tree is processed by the burg compiler to emit x86 machine code. (in the diagram we see registers being assigned to the tree nodes)
The last stage is when I collect the machine code generated by the burg compiler and combine it with data and relocation entries to generate an ELF object file.
I can then pass this to the unix linker (ld) to produce an executable.
ld --dynamic-linker=/lib/ld-linux.so.2 state/start.o state/hello.state.o -ldl -lc -o myhello
Here you can see the disassembled elf object file with relocation entries for the "dlsym" symbol and the "puts" and "hello world" strings.
objdump -d state/hello.state.o -r
Disassembly of section .text: 00000000 <main>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 53 push %ebx 4: 83 ec 14 sub $0x14,%esp 7: bb 00 00 00 00 mov $0x0,%ebx 8: R_386_32 dlsym c: b8 00 00 00 00 mov $0x0,%eax 11: b9 00 00 00 00 mov $0x0,%ecx 12: R_386_32 _data_286 16: 89 4c 24 04 mov %ecx,0x4(%esp) 1a: 89 04 24 mov %eax,(%esp) 1d: ff d3 call *%ebx 1f: 89 c3 mov %eax,%ebx 21: b8 00 00 00 00 mov $0x0,%eax 22: R_386_32 _data_287 26: 89 04 24 mov %eax,(%esp) 29: ff d3 call *%ebx 2b: 89 c0 mov %eax,%eax 2d: 89 c0 mov %eax,%eax 2f: 83 c4 14 add $0x14,%esp 32: 5b pop %ebx 33: 5d pop %ebp 34: c3 ret You can view the code at:
http://subvert-the-dominant-paradigm.net/repos/hgwebdir.cgi/bootstrap/
(click manifest to see the files, or run 'hg clone <url>' to get a local copy)
John Leuner
Currently I have a compiler that can read sexp input, eg:
(define |main| (lambda ()
((call-c |dlsym| 0 "puts") "hello, dynamic world!")))
and then compile it down to a tree of blocks and instruction objects (see instruction.lisp or Instruction.st) BLOCK(--- NIL ---) &n bsp; | | 0(--- VOID BLOCK --- 369 &nbs p; | | | | | 0(+++ REG CALLI4 --- &n bsp; | | | | | | 0(+++ REG CNSTP4 --- reloc ---) & nbsp; | | | | | | 0(+++ REG CNSTI4 --- 0) &nb sp; | | | | | | 0(+++ REG CNSTP4 --- reloc ---)) | | | | | 0(+++ REG CNSTP4 --- reloc ---)) &n bsp; | | 0(--- VOID BLOCK --- 369 &nbs p; | | | | | 0(+++ REG CALLI4 EBX &n bsp; | | | | | | 0(+++ REG CNSTP4 EBX reloc ---) & nbsp; | | | | | | 0(+++ REG CNSTI4 EAX 0) &nb sp; | | | | | | 0(+++ REG CNSTP4 ECX reloc ---)) | | | | | 0(+++ REG CNSTP4 EAX reloc ---))
This tree is processed by the burg compiler to emit x86 machine code. (in the diagram we see registers being assigned to the tree nodes)
The last stage is when I collect the machine code generated by the burg compiler and combine it with data and relocation entries to generate an ELF object file.
I can then pass this to the unix linker (ld) to produce an executable.
ld --dynamic-linker=/lib/ld-linux.so.2 state/start.o state/hello.state.o -ldl -lc -o myhello
Here you can see the disassembled elf object file with relocation entries for the "dlsym" symbol and the "puts" and "hello world" strings.
objdump -d state/hello.state.o -r
Disassembly of section .text: 00000000 <main>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 53 push %ebx 4: 83 ec 14 sub $0x14,%esp 7: bb 00 00 00 00 mov $0x0,%ebx 8: R_386_32 dlsym c: b8 00 00 00 00 mov $0x0,%eax 11: b9 00 00 00 00 mov $0x0,%ecx 12: R_386_32 _data_286 16: 89 4c 24 04 mov %ecx,0x4(%esp) 1a: 89 04 24 mov %eax,(%esp) 1d: ff d3 call *%ebx 1f: 89 c3 mov %eax,%ebx 21: b8 00 00 00 00 mov $0x0,%eax 22: R_386_32 _data_287 26: 89 04 24 mov %eax,(%esp) 29: ff d3 call *%ebx 2b: 89 c0 mov %eax,%eax 2d: 89 c0 mov %eax,%eax 2f: 83 c4 14 add $0x14,%esp 32: 5b pop %ebx 33: 5d pop %ebp 34: c3 ret You can view the code at:
http://subvert-the-dominant-paradigm.net/repos/hgwebdir.cgi/bootstrap/
(click manifest to see the files, or run 'hg clone <url>' to get a local copy)
John Leuner
<div> I've been working on an experimental port of jolt-burg. The main difference is that my implementation language is Common Lisp and that my compiler targets relocatable ELF object files.<br><br> Currently I have a compiler that can read sexp input, eg:<br><br> (define |main| (lambda ()<br> ((call-c |dlsym| 0 "puts") "hello, dynamic world!")))<br><br> and then compile it down to a tree of blocks and instruction objects (see instruction.lisp or Instruction.st) BLOCK(--- NIL ---) &n bsp; | | 0(--- VOID BLOCK --- 369 &nbs p; | | | | | 0(+++ REG CALLI4 --- &n bsp; | | | | | | 0(+++ REG CNSTP4 --- reloc ---) & nbsp; | | | | | | 0(+++ REG CNSTI4 --- 0) &nb sp; | | | | | | 0(+++ REG CNSTP4 --- reloc ---)) | | | | | 0(+++ REG CNSTP4 --- reloc ---)) &n bsp; | | 0(--- VOID BLOCK --- 369 &nbs p; | | | | | 0(+++ REG CALLI4 EBX &n bsp; | | | | | | 0(+++ REG CNSTP4 EBX reloc ---) & nbsp; | | | | | | 0(+++ REG CNSTI4 EAX 0) &nb sp; | | | | | | 0(+++ REG CNSTP4 ECX reloc ---)) | | | | | 0(+++ REG CNSTP4 EAX reloc ---)) <br> This tree is processed by the burg compiler to emit x86 machine code. (in the diagram we see registers being assigned to the tree nodes)<br><br> The last stage is when I collect the machine code generated by the burg compiler and combine it with data and relocation entries to generate an ELF object file.<br><br> I can then pass this to the unix linker (ld) to produce an executable.<br><br> ld --dynamic-linker=/lib/ld-linux.so.2 state/start.o state/hello.state.o -ldl -lc -o myhello<br><br> Here you can see the disassembled elf object file with relocation entries for the "dlsym" symbol and the "puts" and "hello world" strings.<br><br> objdump -d state/hello.state.o -r<br><br> Disassembly of section .text: 00000000 <main>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 53 push %ebx 4: 83 ec 14 sub $0x14,%esp 7: bb 00 00 00 00 mov $0x0,%ebx 8: R_386_32 dlsym c: b8 00 00 00 00 mov $0x0,%eax 11: b9 00 00 00 00 mov $0x0,%ecx 12: R_386_32 _data_286 16: 89 4c 24 04 mov %ecx,0x4(%esp) 1a: 89 04 24 mov %eax,(%esp) 1d: ff d3 call *%ebx 1f: 89 c3 mov %eax,%ebx 21: b8 00 00 00 00 mov $0x0,%eax 22: R_386_32 _data_287 26: 89 04 24 mov %eax,(%esp) 29: ff d3 call *%ebx 2b: 89 c0 mov %eax,%eax 2d: 89 c0 mov %eax,%eax 2f: 83 c4 14 add $0x14,%esp 32: 5b pop %ebx 33: 5d pop %ebp 34: c3 ret You can view the code at:<br><br><a href="http://subvert-the-dominant-paradigm.net/repos/hgwebdir.cgi/bootstrap/">http://subvert-the-dominant-paradigm.net/repos/hgwebdir.cgi/bootstrap/</a><br><br> (click manifest to see the files, or run 'hg clone <url>' to get a local copy)<br><br> John Leuner<br><br> </div>
RSS Feed