Exemple #1
0
        public override void GenCode(StringBuilder sb)
        {
            // if the variable is an argument as opposed to a variable
            // use the ldarg instruction rather than the ldloc instruction
            FormalParam fp = declarationRef as FormalParam;

            if (fp != null)
            {
                cg.emit(sb, "\tldarg.s {0}\n", fp.GetNumber());
            }
            else
            {
                cg.emit(sb, "\tldloc.s {0}\n", declarationRef.GetNumber());
            }
        }
Exemple #2
0
        public override void GenCode(StringBuilder sb)
        {
            cg.emit(sb, ".method ");
            // Check if we have static. If yes then we want to emit it first
            if (methodModifiers.Contains(Modifier.STATIC))
            {
                cg.emit(sb, "static ");
            }
            foreach (var modif in methodModifiers)
            {
                if (modif != Modifier.STATIC)
                {
                    cg.emit(sb, "{0} ", modif.ToString().ToLower());
                }
            }

            //returnType.GenCode(sb);
            cg.emit(sb, "{0} ", returnType.GetILName());
            cg.emit(sb, "{0}", methodIdentifier);
            cg.emit(sb, "(");

            // args do this properly - nathan
            string fp_list = "";

            foreach (Expression each in args)
            {
                FormalParam fp = each as FormalParam;
                if (fp != null)
                {
                    fp_list = fp_list + fp.ObtainType().GetILName() + ' ' + fp.GetName() + ',';
                }
            }
            fp_list = fp_list.TrimEnd(',');// remove last ','
            cg.emit(sb, fp_list + ")\n");

            cg.emit(sb, "{{\n"); // start of method body
            // If the method is called "main" and it has to be static Main, set it as the program entrypoing
            if (methodIdentifier.ToLower() == "main" && methodModifiers.Contains(Modifier.STATIC))
            {
                cg.emit(sb, "\t.entrypoint\n");
            }

            // generate code for the method body statements
            statementList.GenCode(sb);

            cg.emit(sb, "\tret\n");
            cg.emit(sb, "}} {0}", Environment.NewLine); // end of method body
        }