Skip to content

Instantly share code, notes, and snippets.

@mdaisuke
Created February 24, 2013 14:04
Show Gist options
  • Save mdaisuke/5023960 to your computer and use it in GitHub Desktop.
Save mdaisuke/5023960 to your computer and use it in GitHub Desktop.
(Directive ".file\t\"hoge.cb\"")
(Directive ".section\t.rodata")
(Label (NamedSymbol ".LC0"))
(Directive ".string\t\"Hello world\n\"")
(Directive ".text")
(Directive ".globl main")
(Directive ".type\tmain,@function")
(Label (NamedSymbol "main"))
(Instruction "push" "l" (Register BP INT32))
(Instruction "mov" "l" (Register SP INT32) (Register BP INT32))
(Instruction "mov" "l" (ImmediateValue (NamedSymbol ".LC0")) (Register AX INT32))
(Instruction "push" "l" (Register AX INT32))
(Instruction "call" "" (DirectMemoryReference (NamedSymbol "printf")))
(Instruction "add" "l" (ImmediateValue (IntegerLiteral 4)) (Register SP INT32))
(Instruction "mov" "l" (ImmediateValue (IntegerLiteral 0)) (Register AX INT32))
(Instruction "jmp" "" (DirectMemoryReference (UnnamedSymbol @4ca31e1b)))
(Label (UnnamedSymbol @4ca31e1b))
(Instruction "mov" "l" (Register BP INT32) (Register SP INT32))
(Instruction "pop" "l" (Register BP INT32))
(Instruction "ret" "")
(Directive ".size\tmain,.-main")
<<AST>> (hoge.cb:1)
variables:
functions:
<<DefinedFunction>> (hoge.cb:3)
name: "main"
isPrivate: false
params:
parameters:
body:
<<BlockNode>> (hoge.cb:4)
variables:
stmts:
<<ExprStmtNode>> (hoge.cb:5)
expr:
<<FuncallNode>> (hoge.cb:5)
expr:
<<VariableNode>> (hoge.cb:5)
name: "printf"
args:
<<StringLiteralNode>> (hoge.cb:5)
value: "Hello world\n"
<<ReturnNode>> (hoge.cb:6)
expr:
<<IntegerLiteralNode>> (hoge.cb:6)
typeNode: int
value: 0
<<IR>> (hoge.cb:1)
variables:
functions:
<<DefinedFunction>> (hoge.cb:3)
name: main
isPrivate: false
type: int()
body:
<<ExprStmt>> (hoge.cb:5)
expr:
<<Call>>
type: INT32
expr:
<<Addr>>
type: INT32
entity: printf
args:
<<Str>>
type: INT32
entry: net.loveruby.cflat.entity.ConstantEntry@7e5a9de6
<<Return>> (hoge.cb:6)
expr:
<<Int>>
type: INT32
value: 0
<<AST>> (hoge.cb:1)
variables:
functions:
<<DefinedFunction>> (hoge.cb:3)
name: "main"
isPrivate: false
params:
parameters:
body:
<<BlockNode>> (hoge.cb:4)
variables:
stmts:
<<ExprStmtNode>> (hoge.cb:5)
expr:
<<FuncallNode>> (hoge.cb:5)
expr:
<<VariableNode>> (hoge.cb:5)
type: int(char*)*
name: "printf" (resolved)
args:
<<StringLiteralNode>> (hoge.cb:5)
value: "Hello world\n"
<<ReturnNode>> (hoge.cb:6)
expr:
<<IntegerLiteralNode>> (hoge.cb:6)
typeNode: int (resolved)
value: 0
"import" "import"
<SPACES> " "
<IDENTIFIER> "stdio"
";" ";"
<SPACES> "\n\n"
"int" "int"
<SPACES> " "
<IDENTIFIER> "main"
"(" "("
"void" "void"
")" ")"
<SPACES> "\n"
"{" "{"
<SPACES> "\n "
<IDENTIFIER> "printf"
"(" "("
"\"" "\"Hello world\n\""
")" ")"
";" ";"
<SPACES> "\n "
"return" "return"
<SPACES> " "
<INTEGER> "0"
";" ";"
<SPACES> "\n"
"}" "}"
<SPACES> "\n"
<EOF> ""
import stdio;
int main(void)
{
printf("Hello world\n");
return 0;
}
.file "hoge.cb"
.section .rodata
.LC0:
.string "Hello world\n"
.text
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
movl $.LC0, %eax
pushl %eax
call printf
addl $4, %esp
movl $0, %eax
jmp .L0
.L0:
movl %ebp, %esp
popl %ebp
ret
.size main,.-main
.file "hoge.cb"
.section .rodata
.LC0:
.string "Hello world\n"
.text
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
movl $.LC0, %eax
pushl %eax
call printf
addl $4, %esp
movl $0, %eax
jmp .L0
.L0:
movl %ebp, %esp
popl %ebp
ret
.size main,.-main
@mdaisuke
Copy link
Author

tokens -> ast -> semantic(checked ast) -> ir -> asm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment