Posted to tcl by gps at Mon Mar 30 01:42:25 GMT 2009view raw

  1. structure string
  2. integer length
  3. pointer array
  4. end-structure
  5.  
  6. structure main-args
  7. integer count
  8. pointer array
  9. end-structure
  10.  
  11. extern puti
  12. extern putn
  13.  
  14. : main
  15. declare-structure main-args args
  16. declare-structure string s
  17.  
  18. 1 *s.length ->
  19. s.length puti putn
  20.  
  21. args.count if args.count puti then
  22.  
  23. 1 *args.count ->
  24.  
  25. putn
  26. ;;
  27.  
  28.  
  29. ----
  30. Here's the code.S generated and the runtime.S:
  31.  
  32. .globl main
  33. main:
  34. pushl %ebp
  35. movl %esp,%ebp
  36. /*declare-structure begin*/
  37. subl $8,%esp
  38. /*declare-structure end*/
  39. /*declare-structure begin*/
  40. subl $16,%esp
  41. /*declare-structure end*/
  42. /*push-value begin*/
  43. movl creatc_stack_ptr,%eax
  44. subl $4,%eax
  45. movl $1,(%eax)
  46. movl %eax,creatc_stack_ptr
  47. /*push-value end*/
  48. /*push-local begin*/
  49. movl creatc_stack_ptr,%eax
  50. subl $4,%eax
  51. leal -12(%ebp),%ecx
  52. movl %ecx,(%eax)
  53. movl %eax,creatc_stack_ptr
  54. /*push-local end*/
  55. /*op-> begin*/
  56. movl creatc_stack_ptr,%eax
  57. movl (%eax),%ecx
  58. addl $4,%eax
  59. movl (%eax),%edx
  60. movl %edx,(%ecx)
  61. addl $4,%eax
  62. movl %eax,creatc_stack_ptr
  63. /*op-> end*/
  64. /*push-local begin*/
  65. movl creatc_stack_ptr,%eax
  66. subl $4,%eax
  67. movl -12(%ebp),%ecx
  68. movl %ecx,(%eax)
  69. movl %eax,creatc_stack_ptr
  70. /*push-local end*/
  71. /*op-extern-call begin*/
  72. call puti
  73. /*op-extern-call end*/
  74. /*op-extern-call begin*/
  75. call putn
  76. /*op-extern-call end*/
  77. /*push-local begin*/
  78. movl creatc_stack_ptr,%eax
  79. subl $4,%eax
  80. movl -4(%ebp),%ecx
  81. movl %ecx,(%eax)
  82. movl %eax,creatc_stack_ptr
  83. /*push-local end*/
  84. /*op-if begin*/
  85. movl creatc_stack_ptr,%eax
  86. movl (%eax),%ecx
  87. addl $4,%eax
  88. movl %eax,creatc_stack_ptr
  89. cmpl $0,%ecx
  90. je ___then_1
  91. /*op-if end*/
  92. /*push-local begin*/
  93. movl creatc_stack_ptr,%eax
  94. subl $4,%eax
  95. movl -4(%ebp),%ecx
  96. movl %ecx,(%eax)
  97. movl %eax,creatc_stack_ptr
  98. /*push-local end*/
  99. /*op-extern-call begin*/
  100. call puti
  101. /*op-extern-call end*/
  102. /*op-then begin*/
  103. ___then_1:
  104. /*op-then end*/
  105. /*push-value begin*/
  106. movl creatc_stack_ptr,%eax
  107. subl $4,%eax
  108. movl $1,(%eax)
  109. movl %eax,creatc_stack_ptr
  110. /*push-value end*/
  111. /*push-local begin*/
  112. movl creatc_stack_ptr,%eax
  113. subl $4,%eax
  114. leal -4(%ebp),%ecx
  115. movl %ecx,(%eax)
  116. movl %eax,creatc_stack_ptr
  117. /*push-local end*/
  118. /*op-> begin*/
  119. movl creatc_stack_ptr,%eax
  120. movl (%eax),%ecx
  121. addl $4,%eax
  122. movl (%eax),%edx
  123. movl %edx,(%ecx)
  124. addl $4,%eax
  125. movl %eax,creatc_stack_ptr
  126. /*op-> end*/
  127. /*op-extern-call begin*/
  128. call putn
  129. /*op-extern-call end*/
  130. leave
  131. ret
  132.  
  133.  
  134. /************** runtime.S **********************/
  135.  
  136. .section .rodata
  137. int_fmt: .string "%d"
  138. newline_fmt: .string "\n"
  139. .data
  140. .comm creatc_stack, 8192
  141. .globl creatc_stack_ptr
  142. .data
  143. creatc_stack_ptr: .long creatc_stack + 8192
  144. .text
  145.  
  146. .globl puti
  147. puti:
  148. movl creatc_stack_ptr,%eax
  149. movl (%eax),%ecx
  150. addl $4,%eax
  151. movl %eax,creatc_stack_ptr
  152. pushl %ecx
  153. pushl $int_fmt
  154. call printf
  155. addl $8,%esp
  156. ret
  157.  
  158. .globl putn
  159. putn:
  160. pushl $newline_fmt
  161. call printf
  162. addl $4,%esp
  163. ret
  164.  
  165.  
  166.