Compiler Design 2023

Testcase “euclid” of Assignment 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
; Jassmin assembly code
; MiniC v. 1.0
.class public euclid
.super java/lang/Object

.method static <clinit>()V
   .limit stack 1
   .limit locals 0
   return
.end method

.method public <init>()V
   .limit stack 1
   .limit locals 1
   .var 0 is this Leuclid; from Label0 to Label1

  Label0:
   aload_0
   invokespecial java/lang/Object/<init>()V
  Label1:
   return
.end method

.method public gcd(II)I
  Label0:
   ; WhileStmt, line 5
  Label2:
   iload_2
   iconst_0
   if_icmpne Label4
   iconst_0
   goto Label5
  Label4:
   iconst_1
  Label5:
   ifeq Label3
   ; IfStmt, line 10
   iload_1
   iload_2
   if_icmpgt Label6
   iconst_0
   goto Label7
  Label6:
   iconst_1
  Label7:
   ifeq Label8
   ; AssignStmt, line 7
   iload_1
   iload_2
   isub
   istore_1
   goto Label9
  Label8:
   ; AssignStmt, line 9
   iload_2
   iload_1
   isub
   istore_2
  Label9:
   goto Label2
  Label3:
   ; ReturnStmt, line 12
   iload_1
   ireturn
  Label1:
   .limit locals 3
   .limit stack 150
.end method

.method public static main([Ljava/lang/String;)V
  Label0:
   new euclid
   dup
   invokespecial euclid/<init>()V
   astore_1
   ; AssignStmt, line 17
   ; CallExpr
   ; "this"-pointer is the first ActualParam with instance methods:
   aload_1
   ; ActualParam
   bipush 22
   ; ActualParam
   bipush 12
   invokevirtual euclid/gcd(II)I
   istore_2
   ; CallStmt, line 18
   ; CallExpr
   ; ActualParam
   iload_2
   invokestatic lang/System/putInt(I)V
   ; CallStmt, line 19
   ; CallExpr
   invokestatic lang/System/putLn()V
  Label1:
   return
   .limit locals 3
   .limit stack 150
.end method