TC-X FAQ

How to compile and test?

To generate a binary from an IA-32 assembly file:

add-ia32.tig
let
  function add(x: int, y: int) : int = x + y
in
  print_int(add(1,(add(2, 3)))); print("\n")
end
tc -e --target-ia32 --asm-compute --inst-display add-ia32.tig
$ tc -e --target-ia32 --asm-compute --inst-display add-ia32.tig
/** Tiger final assembler ouput. */

/** Routine: add */
	.text
	.globl	tc_l0
	.type	tc_l0,@function
tc_l0:
	pushl	%ebp
	subl	$4, %esp
	movl	%esp, %ebp
	subl	$4, %esp
	movl	12(%ebp), %ecx
	movl	%ecx, (%ebp)
	movl	16(%ebp), %eax
	movl	20(%ebp), %ecx
l2:
	addl	%ecx, %eax
l3:
	addl	$4, %ebp
	leave
	ret	$12
l6:
	.size	tc_l0,l6-tc_l0

	.section	.rodata
l1:
	.long 1
	.asciz "\n"

/** Routine: _main */
	.text
	.globl	tc_main
	.type	tc_main,@function
tc_main:
	pushl	%ebp
	subl	$4, %esp
	movl	%esp, %ebp
	subl	$4, %esp
	movl	%ebx, (%ebp)
l4:
	movl	%ebp, %ebx
	movl	$3, %ecx
	pushl	%ecx
	movl	$2, %ecx
	pushl	%ecx
	pushl	%ebp
	call	tc_l0
	pushl	%eax
	movl	$1, %ecx
	pushl	%ecx
	pushl	%ebx
	call	tc_l0
	pushl	%eax
	call	tc_print_int
	lea	l1, %ecx
	pushl	%ecx
	call	tc_print
l5:
	movl	(%ebp), %ebx
	addl	$4, %ebp
	leave
	ret	$0
l7:
	.size	tc_main,l7-tc_main
	.ident	"LRDE Tiger Compiler"
$ echo $?
0
tc -e --target-ia32 --asm-display add-ia32.tig > add-ia32.s
$ tc -e --target-ia32 --asm-display add-ia32.tig > add-ia32.s

$ echo $?
0
gcc -m32 -oadd-ia32 add-ia32.s
$ gcc -m32 -oadd-ia32 add-ia32.s
/usr/bin/ld: /tmp/cc4DfuXP.o: warning: relocation in read-only section `.text'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
$ echo $?
0
./add-ia32
$ ./add-ia32
6
$ echo $?
0