Skip to content

Example

skyrabbit edited this page Sep 19, 2019 · 6 revisions

hello.grp

int main(void) {
  print "hello world";
  return 0;
}

IR

Constants

String_{ value:"hello world" }

Functions

Function{
  name:"main"
  type:INT
  arguments=[void]
  symbols:[]
  blocks:[
    BasicBlock{
      name:"entry"
      instructions:[
        Print{ Constants[0] }
        Return{}
      ]
    }
  ]
}

hello.ir

@c0 = "hello world"
@main = int(void) {
  entry:
    print @c0
    return 0
}

hello.wc

0xdeadbeef  magic
0x01000000  entry point 1
0x00000000  registers size 0
0x00000000  references size 0
0x01000000  tag 1
0x0c000000  size 12
0x6c6c6568  value "hello world"
0x6f77206f
0x00646c72
0x01000000  1
0x02000000  2
0x30000000  print c0
0x02000000  return 0

Memory

0x# | 0x6c6c6568  "hello world"
    | 0x6f77206f
    | 0x00646c72
0x0 | 0x########  c0
0x1 | 0x30000000  print c0
0x2 | 0x02000000  return 0

hello.s

.intel_syntax noprefix
.Lc0:
        .ascii "hello world\0"
.globl  _main
_main:
        push    rbp
        mov     rbp, rsp
        mov     rdi, [.Lc0]
        call    _printf
        mov     rax, 0     
        mov     rsp, rbp
        pop     rbp
        ret

Clone this wiki locally