public MipsProgram VisitStringConstant(ASTCILStringConstantNode StringConstant)
        {
            var result      = new MipsProgram();
            var stringValue = Regex.Unescape(StringConstant.Value);

            if (!StringConstantGenerated.TryGetValue(StringConstant.Value, out var labelStringConstant))
            {
                result.SectionData.Append(MipsGenerationHelper.NewScript()
                                          .AddData(StringConstant.ObjectLabel,
                                                   new[]
                {
                    MipsGenerationHelper.AddIntData(
                        labelGenerator.GenerateLabelTypeInfo(CompilationUnit.TypeEnvironment.String.Name)),
                    MipsGenerationHelper.AddIntData(StringConstant.ValueLabel),
                    MipsGenerationHelper.AddIntData(stringValue.Length)
                })
                                          .Comment(StringConstant.Value)
                                          .AddData(StringConstant.ValueLabel, new[]
                {
                    MipsGenerationHelper.AddByteData(Regex.Unescape(StringConstant.Value).Select(x => (int)x))
                }));
                StringConstantGenerated.Add(StringConstant.Value, StringConstant.ObjectLabel);
                labelStringConstant = StringConstant.ObjectLabel;
            }

            result.SectionCode.Append(MipsGenerationHelper.NewScript()
                                      .LoadFromAddress(MipsRegisterSet.a0, labelStringConstant)
                                      .Add(MipsRegisterSet.a0, 4));
            return(result);
        }
Exemple #2
0
 public ASTCILNode VisitLetIn(ASTLetInNode LetIn)
 {
     return(new ASTCILBlockNode(LetIn.Declarations.SelectMany(x =>
     {
         ASTCILExpressionNode expression;
         compilationUnit.TypeEnvironment.GetTypeDefinition(x.Type.Text, LetIn.SymbolTable, out var type);
         if (x.Expression != null)
         {
             expression = (ASTCILExpressionNode)x.Expression.Accept(this);
         }
         else if (x.Type.Text == Types.Bool)
         {
             expression = new ASTCILBoolConstantNode(false);
         }
         else if (x.Type.Text == Types.Int)
         {
             expression = new ASTCILIntConstantNode(0);
         }
         else if (x.Type.Text == Types.String)
         {
             expression = new ASTCILStringConstantNode("", labelIlGenerator.GenerateEmptyStringData());
         }
         else
         {
             expression = new ASTCILVoidNode();
         }
         return new ASTCILExpressionNode[]
         {
             new ASTCILAssignmentNode(x.Id, expression)
         };
     }).Append((ASTCILExpressionNode)LetIn.LetExp.Accept(this))));
 }