Docs: for compiler.cfg and compiler.codegen
							parent
							
								
									4cd49e56b2
								
							
						
					
					
						commit
						ea48d13731
					
				| 
						 | 
				
			
			@ -1,13 +1,23 @@
 | 
			
		|||
USING: compiler.cfg help.markup help.syntax vectors ;
 | 
			
		||||
USING: compiler.cfg help.markup help.syntax vectors words ;
 | 
			
		||||
 | 
			
		||||
HELP: basic-block
 | 
			
		||||
{ $class-description
 | 
			
		||||
  "Factors representation of a basic block in the cfg. A basic block is a sequence of instructions that always are executed sequentially and doesn't contain any branching. It has the following slots:"
 | 
			
		||||
  { $table
 | 
			
		||||
    { { $slot "successors" } { "A " { $link vector } " of basic blocks that may be executed directly after this block. Most blocks only have one successor but a block that checks where an if-condition should branch to would have two for example." } }
 | 
			
		||||
    { { $slot "word" } { "The " { $link word } " the cfg is produced of." } }
 | 
			
		||||
  }
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
HELP: <basic-block>
 | 
			
		||||
{ $values { "bb" basic-block } }
 | 
			
		||||
{ $description "Creates a new empty basic block." } ;
 | 
			
		||||
 | 
			
		||||
HELP: cfg
 | 
			
		||||
{ $class-description
 | 
			
		||||
  "Call flow graph. It has the following slots:"
 | 
			
		||||
  { $table
 | 
			
		||||
    { { $slot "entry" } { "Initial " { $link basic-block } " of the graph." } }
 | 
			
		||||
    { { $slot "word" } { "The " { $link word } " the cfg is produced of." } }
 | 
			
		||||
  }
 | 
			
		||||
} ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,9 +11,20 @@ HELP: ##inc-d
 | 
			
		|||
  "An instruction that increases or decreases the data stacks size by n. For example, " { $link 2drop } " decreases it by two and pushing an item increases it by one."
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
HELP: ##prologue
 | 
			
		||||
{ $class-description
 | 
			
		||||
  "An instruction for generating the prologue for a cfg." } ;
 | 
			
		||||
 | 
			
		||||
HELP: ##alien-invoke
 | 
			
		||||
{ $class-description
 | 
			
		||||
  "An instruction for calling a function in a dynamically linked library."
 | 
			
		||||
  "An instruction for calling a function in a dynamically linked library. It has the following slots:"
 | 
			
		||||
  { $table
 | 
			
		||||
    { { $slot "reg-inputs" } { "Registers to use for the arguments to the function call." } }
 | 
			
		||||
    { { $slot "stack-inputs" } { "Stack slots used for the arguments to the function call. Only used if all register arguments are already filled." } }
 | 
			
		||||
    { { $slot "reg-outputs" } { "Register that wil contain the return value of the function call if any." } }
 | 
			
		||||
    { { $slot "symbols" } { "Name of the function to call." } }
 | 
			
		||||
    { { $slot "dll" } { "A dll handle." } }
 | 
			
		||||
  }
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
HELP: ##set-slot
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,76 @@
 | 
			
		|||
USING: alien byte-arrays compiler.cfg help.markup help.syntax literals
 | 
			
		||||
multiline sequences ;
 | 
			
		||||
IN: compiler.codegen
 | 
			
		||||
 | 
			
		||||
<<
 | 
			
		||||
STRING: generate-ex
 | 
			
		||||
USING: compiler.cfg.debugger io prettyprint ;
 | 
			
		||||
[ "hello\n" write ] test-regs first dup cfg set generate [ . ] [ 4 swap nth disassemble ] bi
 | 
			
		||||
{
 | 
			
		||||
    { }
 | 
			
		||||
    { "hello\n" output-stream assoc-stack stream-write }
 | 
			
		||||
    B{
 | 
			
		||||
        6 0 0 242 24 0 0 96 49 0 0 96 58 0 0 34 64 0 0 242 80 0
 | 
			
		||||
        0 50
 | 
			
		||||
    }
 | 
			
		||||
    { }
 | 
			
		||||
    B{
 | 
			
		||||
        137 5 0 0 0 0 72 131 236 8 73 131 198 24 72 185 0 0 0 0
 | 
			
		||||
        0 0 0 0 73 137 78 240 73 139 77 0 72 139 73 64 73 137 14
 | 
			
		||||
        72 185 0 0 0 0 0 0 0 0 73 137 78 248 232 0 0 0 0 137 5 0
 | 
			
		||||
        0 0 0 72 131 196 8 72 141 29 5 0 0 0 233 0 0 0 0 0 0 0 0
 | 
			
		||||
        0 0 0 0 0 0 0 0 0 0 0 0
 | 
			
		||||
    }
 | 
			
		||||
    16
 | 
			
		||||
}
 | 
			
		||||
0000000001cc4ca0: 890500000000          mov [rip], eax
 | 
			
		||||
0000000001cc4ca6: 4883ec08              sub rsp, 0x8
 | 
			
		||||
0000000001cc4caa: 4983c618              add r14, 0x18
 | 
			
		||||
0000000001cc4cae: 48b90000000000000000  mov rcx, 0x0
 | 
			
		||||
0000000001cc4cb8: 49894ef0              mov [r14-0x10], rcx
 | 
			
		||||
0000000001cc4cbc: 498b4d00              mov rcx, [r13]
 | 
			
		||||
0000000001cc4cc0: 488b4940              mov rcx, [rcx+0x40]
 | 
			
		||||
0000000001cc4cc4: 49890e                mov [r14], rcx
 | 
			
		||||
0000000001cc4cc7: 48b90000000000000000  mov rcx, 0x0
 | 
			
		||||
0000000001cc4cd1: 49894ef8              mov [r14-0x8], rcx
 | 
			
		||||
0000000001cc4cd5: e800000000            call 0x1cc4cda
 | 
			
		||||
0000000001cc4cda: 890500000000          mov [rip], eax
 | 
			
		||||
0000000001cc4ce0: 4883c408              add rsp, 0x8
 | 
			
		||||
0000000001cc4ce4: 488d1d05000000        lea rbx, [rip+0x5]
 | 
			
		||||
0000000001cc4ceb: e900000000            jmp 0x1cc4cf0
 | 
			
		||||
0000000001cc4cf0: 0000                  add [rax], al
 | 
			
		||||
0000000001cc4cf2: 0000                  add [rax], al
 | 
			
		||||
0000000001cc4cf4: 0000                  add [rax], al
 | 
			
		||||
0000000001cc4cf6: 0000                  add [rax], al
 | 
			
		||||
0000000001cc4cf8: 0000                  add [rax], al
 | 
			
		||||
0000000001cc4cfa: 0000                  add [rax], al
 | 
			
		||||
0000000001cc4cfc: 0000                  add [rax], al
 | 
			
		||||
0000000001cc4cfe: 0000                  add [rax], al
 | 
			
		||||
;
 | 
			
		||||
>>
 | 
			
		||||
 | 
			
		||||
HELP: generate
 | 
			
		||||
{ $values { "cfg" cfg } { "code" sequence } }
 | 
			
		||||
{ $description "Generates assembly code for the given cfg. The output " { $link sequence } " has six items with the following interpretations:"
 | 
			
		||||
  { $list
 | 
			
		||||
    { "The first element is a sequence of alien function symbols and " { $link dll } "s used by the cfg interleaved." }
 | 
			
		||||
    "The second item is the parameter table."
 | 
			
		||||
    "The third item is the literal table."
 | 
			
		||||
    { "The third item is the relocation table as a " { $link byte-array } "." }
 | 
			
		||||
    "The fourth item is the label table."
 | 
			
		||||
    { "The fifth item is the generated assembly code as a " { $link byte-array } ". It still contains unresolved crossreferences." }
 | 
			
		||||
    "The sixth item is the size of the stack frame in bytes."
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
{ $examples
 | 
			
		||||
  "A small quotation is compiled and then disassembled:"
 | 
			
		||||
  { $unchecked-example $[ generate-ex ] }
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
HELP: useless-branch?
 | 
			
		||||
{ $values
 | 
			
		||||
  { "bb" basic-block }
 | 
			
		||||
  { "successor" "The successor block of bb" }
 | 
			
		||||
  { "?" "A boolean value" }
 | 
			
		||||
}
 | 
			
		||||
{ $description "If successor immediately follows bb in the linearization order, then a branch is is not needed." } ;
 | 
			
		||||
		Loading…
	
		Reference in New Issue