USING: alien byte-arrays compiler.cfg compiler.cfg.instructions
-compiler.codegen.labels compiler.codegen.relocation cpu.architecture hashtables
-help.markup help.syntax literals make multiline sequences ;
+compiler.codegen.labels compiler.codegen.relocation cpu.architecture
+hashtables help.markup help.syntax literals make multiline quotations
+sequences ;
IN: compiler.codegen
<<
}
{ $description "If successor immediately follows bb in the linearization order, then a branch is is not needed." } ;
-HELP: init-fixup
-{ $description "Initializes variables needed for fixup." } ;
-
HELP: check-fixup
{ $values { "seq" "a " { $link sequence } " of generated machine code." } }
{ $description "Used by " { $link with-fixup } " to ensure that the generated machine code is properly aligned." } ;
-ARTICLE: "compiler.codegen" "Code generation from MR (machine representation)" "Code generators for cfg instructions." ;
+HELP: with-fixup
+{ $values
+ { "quot" quotation }
+ { "code" sequence }
+}
+{ $description "Runs the quotation to emit compiled code. The output is a six-tuple with the same format as the one outputted by " { $link generate } "." } ;
+
+ARTICLE: "compiler.codegen" "Code generation from MR (machine representation)"
+"Code generators for cfg instructions."
+$nl
+"Combinators:"
+{ $subsections with-fixup } ;
ABOUT: "compiler.codegen"
instructions>> [ generate-insn ] each
] tri ;
-: init-fixup ( -- )
- V{ } clone label-table set
- V{ } clone binary-literal-table set ;
-
: check-fixup ( seq -- )
length data-alignment get mod 0 assert= ;
init-relocation
V{ } clone return-addresses set
V{ } clone gc-maps set
- init-fixup
+ V{ } clone label-table set
+ V{ } clone binary-literal-table set
[
@
emit-binary-literals
STRING: ex-%box-alien
USING: compiler.codegen compiler.codegen.relocation cpu.architecture make ;
-init-fixup init-relocation [ RAX RBX RCX %box-alien ] B{ } make disassemble
-000000e9fcc720a0: 48b80100000000000000 mov rax, 0x1
+[ RAX RBX RCX %box-alien ] with-fixup 4 swap nth disassemble
+000000e9fcc720a0: 48b80100000000000000 mov eax, 0x1
000000e9fcc720aa: 4885db test rbx, rbx
000000e9fcc720ad: 0f8400000000 jz dword 0xe9fcc720b3
000000e9fcc720b3: 498d4d10 lea rcx, [r13+0x10]