コード例 #1
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
        public FlatOperand AsRValue(FlatValue immediate_value)
        {
            if (OperandType != FlatOperandType.OPND_IMMEDIATE)
                throw new NotSupportedException("Can only turn OPND_IMMEDIATE into RValue");

            if (ImmediateValue.ValueType == FlatValueType.VT_Int32)
            {
                return FlatOperand.RegisterRef((int)ImmediateValue.Object,immediate_value);
            }

            throw new NotImplementedException("ImmediateValue type "+ImmediateValue.ValueType.ToString());
        }
コード例 #2
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 //public string IdentifierName { get; private set; }
 public FlatOperand WithImmediateValue(FlatValue newValue)
 {
     return new FlatOperand(OperandType, OperandIndex, newValue);
 }
コード例 #3
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 public static FlatOperand RegisterRef(int nRegister, FlatValue flatvalue)
 {
     return new FlatOperand(FlatOperandType.OPND_REGISTER_VALUEREF, nRegister, flatvalue);
 }
コード例 #4
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 public static FlatOperand ThisRef(FlatValue flatvalue)
 {
     return new FlatOperand(FlatOperandType.OPND_THIS, flatvalue);
 }
コード例 #5
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 public static FlatOperand Immediate(FlatValue value)
 {
     return new FlatOperand(FlatOperandType.OPND_IMMEDIATE, value);
 }
コード例 #6
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 public static FlatOperand InputRef(int nValue, FlatValue flatvalue)
 {
     return new FlatOperand(FlatOperandType.OPND_INPUT_VALUEREF, nValue,flatvalue );
 }
コード例 #7
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 public static FlatOperand FieldRef(int nRegister, FlatValue flatvalue)
 {
     return new FlatOperand(FlatOperandType.OPND_FIELD_VALUEREF, nRegister, flatvalue);
 }
コード例 #8
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 public static FlatOperand FunctionValueRef(int nValue, FlatValue flatvalue)
 {
     return new FlatOperand(FlatOperandType.OPND_FUNCTION_VALUEREF, nValue, flatvalue);
 }
コード例 #9
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 private FlatOperand(FlatOperandType type, FlatValue imm)
 {
     OperandType = type;
     ImmediateValue = imm;
 }
コード例 #10
0
ファイル: FlatStatement.cs プロジェクト: LaxLacks/ls2csc
 private FlatOperand(FlatOperandType type, int index, FlatValue imm)
 {
     OperandType = type;
     ImmediateValue = imm;
     OperandIndex = index;
 }
コード例 #11
0
 public void Add(FlatValue val)
 {
     Values.Add(val);
 }
コード例 #12
0
 public void Add(string key, FlatValue val)
 {
     Values.Add(key, val);
 }
コード例 #13
0
ファイル: Function.cs プロジェクト: VendanAndrews/ls2csc
        public FlatOperand ResolveArgumentsToArray(ArgumentListSyntax args, FlatOperand return_reference, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            if (into_lvalue == null)
            {
                FlatOperand register_fop = AllocateRegister("");
                into_lvalue = register_fop.GetLValue(this, instructions);
            }

            FlatValue literalArray;
            FlatOperand fop_array;

            bool allLiteral = (return_reference==null);
            if (allLiteral)
            {
                foreach (ArgumentSyntax ars in args.Arguments)
                {
                    /*
                            // Summary:
                            //     ExpressionSyntax node representing the argument.
                            public ExpressionSyntax Expression { get; }
                            //
                            // Summary:
                            //     NameColonSyntax node representing the optional name arguments.
                            public NameColonSyntax NameColon { get; }
                            //
                            // Summary:
                            //     SyntaxToken representing the optional ref or out keyword.
                            public SyntaxToken RefOrOutKeyword { get; }
                    /**/
                    if (ars.NameColon != null)
                    {
                        throw new NotImplementedException("name : value");
                    }
                    if (ars.RefOrOutKeyword.Kind != SyntaxKind.None)
                    {
                        throw new NotImplementedException("ref/out keywords");
                    }

                    if (!(ars.Expression is LiteralExpressionSyntax))
                    {
                        allLiteral = false;
                    }
                }

                if (allLiteral)
                {
                    FlatArrayBuilder fab = new FlatArrayBuilder();

                    foreach (ArgumentSyntax ars in args.Arguments)
                    {
                        LiteralExpressionSyntax les = (LiteralExpressionSyntax)ars.Expression;
                        // get the type
                        TypeInfo ti = Model.GetTypeInfo(les);
                        FlatOperand fop_element = ResolveExpression(les, ti.ConvertedType);
                        fab.Add(fop_element.ImmediateValue);
                    }

                    literalArray = fab.GetFlatValue();
                    instructions.Add(FlatStatement.DUPLICATE(into_lvalue, FlatOperand.Immediate(literalArray)));
                    fop_array = into_lvalue.AsRValue(literalArray);
                    return fop_array;
                }
            }

            // generate a new array
            literalArray = new FlatValue(FlatValueType.VT_Array, "{ }", null);
            instructions.Add(FlatStatement.DUPLICATE(into_lvalue, FlatOperand.Immediate(literalArray)));

            fop_array = into_lvalue.AsRValue(literalArray);

            if (return_reference != null)
            {
                instructions.Add(FlatStatement.ADD(into_lvalue, fop_array, return_reference));
            }

            foreach(ArgumentSyntax ars in args.Arguments)
            {
                /*
                        // Summary:
                        //     ExpressionSyntax node representing the argument.
                        public ExpressionSyntax Expression { get; }
                        //
                        // Summary:
                        //     NameColonSyntax node representing the optional name arguments.
                        public NameColonSyntax NameColon { get; }
                        //
                        // Summary:
                        //     SyntaxToken representing the optional ref or out keyword.
                        public SyntaxToken RefOrOutKeyword { get; }
                /**/
                FlatOperand fop_element = ResolveExpression(ars.Expression, null, instructions);
                instructions.Add(FlatStatement.ADD(into_lvalue,fop_array,fop_element));
            }

            return fop_array;
        }
コード例 #14
0
ファイル: Function.cs プロジェクト: LaxLacks/ls2csc
        public FlatOperand ResolveExpressionsToArray(IEnumerable<ExpressionSyntax> expressions, FlatOperand return_reference, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            if (into_lvalue == null)
            {
                FlatOperand register_fop = AllocateRegister("");
                into_lvalue = register_fop.GetLValue(this, instructions);
            }

            FlatValue literalArray;
            FlatOperand fop_array;

            bool allLiteral = (return_reference == null);
            if (allLiteral)
            {
                foreach (ExpressionSyntax es in expressions)
                {
                    if (!(es is LiteralExpressionSyntax))
                    {
                        allLiteral = false;
                    }
                }

                if (allLiteral)
                {
                    FlatArrayBuilder fab = new FlatArrayBuilder();

                    foreach (ExpressionSyntax es in expressions)
                    {
                        LiteralExpressionSyntax les = (LiteralExpressionSyntax)es;
                        // get the type
                        TypeInfo ti = Model.GetTypeInfo(les);
                        FlatOperand fop_element = ResolveExpression(les, ti.ConvertedType);
                        fab.Add(fop_element.ImmediateValue);
                    }

                    literalArray = fab.GetFlatValue();
                   // if (literalArray.ToString().Length < 192) // max instruction size is 255 bytes, this has to fit
                    {
                        instructions.Add(FlatStatement.DUPLICATE(into_lvalue, FlatOperand.Immediate(literalArray)));
                        fop_array = into_lvalue.AsRValue(literalArray);
                        return fop_array;
                    }
                }
            }

            // generate a new array
            literalArray = new FlatValue(FlatValueType.VT_Array, "{ }", null);
            instructions.Add(FlatStatement.DUPLICATE(into_lvalue, FlatOperand.Immediate(literalArray)));

            fop_array = into_lvalue.AsRValue(literalArray);

            if (return_reference != null)
            {
                instructions.Add(FlatStatement.ADD(into_lvalue, fop_array, return_reference));
            }

            foreach (ExpressionSyntax es in expressions)
            {
                /*
                        // Summary:
                        //     ExpressionSyntax node representing the argument.
                        public ExpressionSyntax Expression { get; }
                        //
                        // Summary:
                        //     NameColonSyntax node representing the optional name arguments.
                        public NameColonSyntax NameColon { get; }
                        //
                        // Summary:
                        //     SyntaxToken representing the optional ref or out keyword.
                        public SyntaxToken RefOrOutKeyword { get; }
                /**/
                FlatOperand fop_element = ResolveExpression(es, null, instructions);
                instructions.Add(FlatStatement.ADD(into_lvalue, fop_array, fop_element));
            }

            return fop_array;
        }
コード例 #15
0
ファイル: Function.cs プロジェクト: LaxLacks/ls2csc
        public FlatOperand Resolve(ObjectCreationExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            /*
            // Summary:
            //     ArgumentListSyntax representing the list of arguments passed as part of the
            //     object creation expression.
            public ArgumentListSyntax ArgumentList { get; }
            //
            // Summary:
            //     InitializerExpressionSyntax representing the initializer expression for the
            //     object being created.
            public InitializerExpressionSyntax Initializer { get; }
            //
            // Summary:
            //     SyntaxToken representing the new keyword.
            public SyntaxToken NewKeyword { get; }
            //
            // Summary:
            //     TypeSyntax representing the type of the object being created.
            public TypeSyntax Type { get; }
             */
            TypeInfo ti = Model.GetTypeInfo(node);

            if (ti.Type.TypeKind == TypeKind.Delegate)
            {
                // NEW destination, type, arguments
                if (into_lvalue == null)
                {
                    FlatOperand register_fop = AllocateRegister("");
                    into_lvalue = register_fop.GetLValue(this, instructions);
                }

                FlatOperand fop_type = Resolve(ti.ConvertedType, null, instructions);

                FlatOperand arrayregister_fop = AllocateRegister("");
                FlatOperand array_lvalue = arrayregister_fop.GetLValue(this, instructions);

                FlatValue literalArray = new FlatValue(FlatValueType.VT_Array, "{ }", null);
                instructions.Add(FlatStatement.DUPLICATE(array_lvalue, FlatOperand.Immediate(literalArray)));

                ExpressionSyntax expr = node.ArgumentList.Arguments[0].Expression;

                SymbolInfo si = Model.GetSymbolInfo(expr);
                if (si.Symbol.Kind != SymbolKind.Method)
                {
                    throw new NotSupportedException("Non-method delegate construction");
                }

                FlatOperand fop_method = ResolveExpression(expr, null, instructions);
                instructions.Add(FlatStatement.ADD(array_lvalue, arrayregister_fop, fop_method));

                if (!si.Symbol.IsStatic)
                {
                    FlatOperand fop_subject = ResolveParentExpression(si,expr,null,null,instructions);

                    instructions.Add(FlatStatement.ADD(array_lvalue, arrayregister_fop, fop_subject));
                }

                instructions.Add(FlatStatement.NEWDELEGATE(into_lvalue, fop_type, arrayregister_fop));

                FlatOperand fop_rvalue = into_lvalue.AsRValue(FlatValue.FromType(ti.ConvertedType));
                return fop_rvalue;
            }

            {
                SymbolInfo si = Model.GetSymbolInfo(node);

                if (si.Symbol.Kind != SymbolKind.Method)
                {
                    throw new NotSupportedException("new without Constructor method?");
                }
                // NEW destination, type, arguments
                if (into_lvalue == null)
                {
                    FlatOperand register_fop = AllocateRegister("");
                    into_lvalue = register_fop.GetLValue(this, instructions);
                }

                FlatOperand fop_type = Resolve(ti.ConvertedType, null, instructions);

                if (si.Symbol.IsImplicitlyDeclared)
                {
                    Chunk.AddFunction((IMethodSymbol)si.Symbol, Model);
                }

                FlatOperand fop_constructor = Resolve((IMethodSymbol)si.Symbol, fop_type, null, instructions);

                List<ReferencedArgument> references = null;
                FlatOperand fop_args = ResolveArgumentsToArray(node.ArgumentList, null, null, out references, instructions);

                instructions.Add(FlatStatement.NEWOBJECT(into_lvalue, fop_constructor, fop_args));

                DereferenceArgumentsAfterCall(references, instructions);

                FlatOperand fop_rvalue = into_lvalue.AsRValue(FlatValue.FromType(ti.ConvertedType));

                if (node.Initializer != null)
                {
                    // throw new NotImplementedException("new with initializer");

                    // apply statements from the initializer.
                    foreach (ExpressionSyntax es in node.Initializer.Expressions)
                    {
                        if (es is BinaryExpressionSyntax)
                        {
                            BinaryExpressionSyntax bes = (BinaryExpressionSyntax)es;
                            ResolveExpression(bes, result_type, null, fop_rvalue, instructions);
                        }
                        else
                        {
                            ResolveExpression(es, null, instructions);
                        }
                        /*
                        if (node.IsAssignment())
                        {
                            return ResolveAssignmentExpression(node, result_type, into_lvalue, null, instructions);
                        }
                        /**/
                    }
                }
                return fop_rvalue;
            }
        }