Compilerbauhome Compilerbau: Codeerzeugung für Anweisungen Prof. Dr. Uwe Schmidt FH Wedel

Codeerzeugung für Anweisungen


weiter

Übersetzung von Anweisungen: ppl/examples/stmt.ppl

   1begin
   2 var
   3  i,j : int := 7, 3;
   4
   5  -- if statement
   6
   7  if i < j
   8  then
   9    ij := ji
  10  elseif i = j
  11  then
  12    ij := i - 1, j + 1
  13  else
  14    i := i+1
  15  endif;
  16
  17  -- while loop
  18
  19  while i < j
  20  do
  21    ij := i + 1, j - 1
  22  endwhile;
  23
  24  -- repeat loop
  25
  26  repeat
  27    i := i + 1
  28  until i > j;
  29
  30  -- block
  31
  32  begin
  33   var
  34   k : int := i;
  35   var
  36   j : int := k;
  37
  38   j := i;
  39   k := j
  40
  41  end
  42
  43end
weiter

weiter

Anweisungen: der attributierte Programmbaum: ppl/examples/stmt.check

   1---"sequence" (VoidType)
   2   |
   3   +---"begin" (VoidType)
   4       |
   5       +---"sequence" (VoidType)
   6           |
   7           +---"decl" (VoidType)
   8           |   |
   9           |   +---"id" i (IntType)
  10           |
  11           +---"decl" (VoidType)
  12           |   |
  13           |   +---"id" j (IntType)
  14           |
  15           +---":=" (VoidType)
  16           |   |
  17           |   +---"id" i (IntType)
  18           |   |
  19           |   +---"id" j (IntType)
  20           |   |
  21           |   +---(IntType)
  22           |   |
  23           |   +---(IntType)
  24           |
  25           +---"if" (VoidType)
  26           |   |
  27           |   +---"lti" (BoolType)
  28           |   |   |
  29           |   |   +---"id" i (IntType)
  30           |   |   |
  31           |   |   +---"id" j (IntType)
  32           |   |
  33           |   +---"begin" (VoidType)
  34           |   |   |
  35           |   |   +---"sequence" (VoidType)
  36           |   |       |
  37           |   |       +---":=" (VoidType)
  38           |   |           |
  39           |   |           +---"id" i (IntType)
  40           |   |           |
  41           |   |           +---"id" j (IntType)
  42           |   |           |
  43           |   |           +---"id" j (IntType)
  44           |   |           |
  45           |   |           +---"id" i (IntType)
  46           |   |
  47           |   +---"if" (VoidType)
  48           |       |
  49           |       +---"eqi" (BoolType)
  50           |       |   |
  51           |       |   +---"id" i (IntType)
  52           |       |   |
  53           |       |   +---"id" j (IntType)
  54           |       |
  55           |       +---"begin" (VoidType)
  56           |       |   |
  57           |       |   +---"sequence" (VoidType)
  58           |       |       |
  59           |       |       +---":=" (VoidType)
  60           |       |           |
  61           |       |           +---"id" i (IntType)
  62           |       |           |
  63           |       |           +---"id" j (IntType)
  64           |       |           |
  65           |       |           +---"subi" (IntType)
  66           |       |           |   |
  67           |       |           |   +---"id" i (IntType)
  68           |       |           |   |
  69           |       |           |   +---(IntType)
  70           |       |           |
  71           |       |           +---"addi" (IntType)
  72           |       |               |
  73           |       |               +---"id" j (IntType)
  74           |       |               |
  75           |       |               +---(IntType)
  76           |       |
  77           |       +---"begin" (VoidType)
  78           |           |
  79           |           +---"sequence" (VoidType)
  80           |               |
  81           |               +---":=" (VoidType)
  82           |                   |
  83           |                   +---"id" i (IntType)
  84           |                   |
  85           |                   +---"addi" (IntType)
  86           |                       |
  87           |                       +---"id" i (IntType)
  88           |                       |
  89           |                       +---(IntType)
  90           |
  91           +---"while" (VoidType)
  92           |   |
  93           |   +---"lti" (BoolType)
  94           |   |   |
  95           |   |   +---"id" i (IntType)
  96           |   |   |
  97           |   |   +---"id" j (IntType)
  98           |   |
  99           |   +---"begin" (VoidType)
 100           |       |
 101           |       +---"sequence" (VoidType)
 102           |           |
 103           |           +---":=" (VoidType)
 104           |               |
 105           |               +---"id" i (IntType)
 106           |               |
 107           |               +---"id" j (IntType)
 108           |               |
 109           |               +---"addi" (IntType)
 110           |               |   |
 111           |               |   +---"id" i (IntType)
 112           |               |   |
 113           |               |   +---(IntType)
 114           |               |
 115           |               +---"subi" (IntType)
 116           |                   |
 117           |                   +---"id" j (IntType)
 118           |                   |
 119           |                   +---(IntType)
 120           |
 121           +---"repeat" (VoidType)
 122           |   |
 123           |   +---"begin" (VoidType)
 124           |   |   |
 125           |   |   +---"sequence" (VoidType)
 126           |   |       |
 127           |   |       +---":=" (VoidType)
 128           |   |           |
 129           |   |           +---"id" i (IntType)
 130           |   |           |
 131           |   |           +---"addi" (IntType)
 132           |   |               |
 133           |   |               +---"id" i (IntType)
 134           |   |               |
 135           |   |               +---(IntType)
 136           |   |
 137           |   +---"gti" (BoolType)
 138           |       |
 139           |       +---"id" i (IntType)
 140           |       |
 141           |       +---"id" j (IntType)
 142           |
 143           +---"begin" (VoidType)
 144           |   |
 145           |   +---"sequence" (VoidType)
 146           |       |
 147           |       +---"decl" (VoidType)
 148           |       |   |
 149           |       |   +---"id" k (IntType)
 150           |       |
 151           |       +---":=" (VoidType)
 152           |       |   |
 153           |       |   +---"id" k (IntType)
 154           |       |   |
 155           |       |   +---"id" i (IntType)
 156           |       |
 157           |       +---"decl" (VoidType)
 158           |       |   |
 159           |       |   +---"id" j (IntType)
 160           |       |
 161           |       +---":=" (VoidType)
 162           |       |   |
 163           |       |   +---"id" j (IntType)
 164           |       |   |
 165           |       |   +---"id" k (IntType)
 166           |       |
 167           |       +---":=" (VoidType)
 168           |       |   |
 169           |       |   +---"id" j (IntType)
 170           |       |   |
 171           |       |   +---"id" i (IntType)
 172           |       |
 173           |       +---":=" (VoidType)
 174           |       |   |
 175           |       |   +---"id" k (IntType)
 176           |       |   |
 177           |       |   +---"id" j (IntType)
 178           |       |
 179           |       +---":=" (VoidType)
 180           |       |   |
 181           |       |   +---"id" k (IntType)
 182           |       |   |
 183           |       |   +---UndefVal (IntType)
 184           |       |
 185           |       +---":=" (VoidType)
 186           |           |
 187           |           +---"id" j (IntType)
 188           |           |
 189           |           +---UndefVal (IntType)
 190           |
 191           +---":=" (VoidType)
 192           |   |
 193           |   +---"id" i (IntType)
 194           |   |
 195           |   +---UndefVal (IntType)
 196           |
 197           +---":=" (VoidType)
 198               |
 199               +---"id" j (IntType)
 200               |
 201               +---UndefVal (IntType)
weiter

weiter

Anweisungen: der Assemblercode: ppl/examples/stmt.gencode

   1.text
   2        loadi   7
   3        loadi   3
   4        store   m[1]
   5        store   m[0]
   6        load    m[1]
   7        load    m[0]
   8        gti
   9        brfalse l0
  10        load    m[1]
  11        load    m[0]
  12        store   m[1]
  13        store   m[0]
  14        jmp     l1
  15l0:
  16        load    m[0]
  17        load    m[1]
  18        eqi
  19        brfalse l2
  20        load    m[0]
  21        loadi   1
  22        subi
  23        load    m[1]
  24        loadi   1
  25        addi
  26        store   m[1]
  27        store   m[0]
  28        jmp     l3
  29l2:
  30        load    m[0]
  31        loadi   1
  32        addi
  33        store   m[0]
  34l3:
  35l1:
  36        jmp     l4
  37l5:
  38        load    m[0]
  39        loadi   1
  40        addi
  41        load    m[1]
  42        loadi   1
  43        subi
  44        store   m[1]
  45        store   m[0]
  46l4:
  47        load    m[1]
  48        load    m[0]
  49        gti
  50        brtrue  l5
  51l6:
  52        load    m[0]
  53        loadi   1
  54        addi
  55        store   m[0]
  56        load    m[0]
  57        load    m[1]
  58        gti
  59        brfalse l6
  60        load    m[0]
  61        store   m[2]
  62        load    m[2]
  63        store   m[3]
  64        load    m[0]
  65        store   m[3]
  66        load    m[3]
  67        store   m[2]
  68        undef
  69        store   m[2]
  70        undef
  71        store   m[3]
  72        undef
  73        store   m[0]
  74        undef
  75        store   m[1]
  76        terminate
  77
  78.data   4
weiter

Letzte Änderung: 14.02.2012
© Prof. Dr. Uwe Schmidt
Prof. Dr. Uwe Schmidt FH Wedel