Beispiel #1
0
        public override void OnCodeGenVisit(AssemblyGenerator assembler)
        {
            foreach (FormalArgument arg in ArgumentList)
            {
                assembler.AllocMemory(Block.BlockId, arg);
            }
            assembler.EmitCode($"{this.symbol.AsmLabel}:");
            assembler.EmitCode($"\tpushl %ebp");
            assembler.EmitCode($"\tmovl %esp, %ebp");
            assembler.EmitCode($"\tandl $-16, %esp");
            int TotalBytes = assembler.GetParameterBytes(Block.BlockId);

            if (TotalBytes != 0)
            {
                assembler.EmitCode($"\tsubl ${(TotalBytes >= 16 ? TotalBytes : 16)}, %esp");
            }
            if (Identifier.IdentifierName == "main")
            {
                assembler.EmitCode($"\tcall ___main");
                foreach (Statement s in Block.Statements.Where(s => s.Type == SyntaxNodeType.ReturnStatement))
                {
                    ((ReturnStatement)s).ShouldPause = true;
                }
            }
            Block.OnCodeGenVisit(assembler);
            //assembler.EmitCode($"\tleave");
            //assembler.EmitCode($"\tret");
        }
Beispiel #2
0
 public override void OnCodeGenVisit(AssemblyGenerator assembler)
 {
     assembler.AllocMemory(Identifier);
     if (Init != null)
     {
         Init.OnCodeGenVisit(assembler);
         string postfix = ((VariableSymbol)symbol).VariableType == VariableType.Char ? "b" : "l";
         string target  = ((VariableSymbol)symbol).VariableType == VariableType.Char ? "%al" : "%eax";
         assembler.EmitCode($"\tmov{postfix} {target}, {assembler.GetVariableOffset(this.Identifier)}(%ebp)");
     }
 }