Beispiel #1
0
 public void Accept(CIL_OneType ot)
 {
     throw new System.NotImplementedException();
 }
Beispiel #2
0
        public void Accept(CIL_OneType ot)
        {
            Data += "vt." + ot.name + ": .word ";

            if (Clases[ot.name].Father != null)
            {
                Data += "vt." + Clases[ot.name].Father.Name + ", ";
            }
            else
            {
                Data += "0, ";
            }

            int offset = 1;

            // ot.Methods en Item1 tiene los nombres de los metodos como tal
            // y en Item2 esta el nombre de los metodos dentro de la clase
            foreach (var method in ot.Methods)
            {
                Data += method.Item2 + ", ";

                if (!VT.ContainsKey(method.Item1))
                {
                    VT[method.Item1] = offset;
                }

                offset++;
            }

            Data += "0 \n";

            string msgName = "str" + GetNum();

            Data += msgName + ": .asciiz \"" + ot.name + "\"\n";

            Text += ot.name + ".constructor:\n";

            Text += "\t sw $zero, 0($sp) \n" +
                    "\t sw $ra, -4($sp) \n" +
                    "\t sw $fp, -8($sp) \n" +
                    "\t subu $sp, $sp, " + 12 + "\n" +
                    "\t addu $fp, $sp, " + 12 + "\n\n";

            int space = 4 * (ot.Attributes.Count + 3);

            Text += "\t li $v0, 9 \n" +
                    "\t li $a0, " + space + "\n" +
                    "\t syscall \n";

            Text += "\t sw $a0, 0($v0) \n" +
                    "\t la $a0, " + msgName + "\n" +
                    "\t sw $a0, 4($v0) \n";

            Text += "\t la $a0, vt." + ot.name + "\n" +
                    "\t sw $a0, 8($v0) \n";

            for (int i = 0; i < ot.Attributes.Count; i++)
            {
                int temp = 4 * (3 + i);
                Text += "\t li $a0, 0 \n" +
                        "\t sw $a0, " + temp + "($v0) \n";
            }

            Text += "\n\t lw $ra, -4($fp) \n" +
                    "\t lw $fp, -8($fp) \n" +
                    "\t addu $sp, $sp, " + 12 + "\n" +
                    "\t j $ra \n" +
                    "#########################################################################\n";
        }