예제 #1
0
        protected override bool ParseCilInstructionInternal(Instruction instruction,
                                                            ProgramState state)
        {
            switch (instruction.OpCode.Code)
            {
            case Code.Newarr:
                Typ arrayContentType;
                // The array is one-dimensional.
                if (instruction.Operand is TypeReference instructionType)
                {
                    arrayContentType = Typ.FromTypeReference(instructionType);
                }
                // Then the content type of the array is an array (it is multidimensional).
                else if (instruction.Operand is ArrayType instructionArrayType)
                {
                    // Creates a SIL representation of the array content type.
                    arrayContentType = CreateArrayType(
                        Typ.FromTypeReference(instructionArrayType.GetElementType()),
                        instructionArrayType.Rank, state);
                }
                else
                {
                    Log.WriteParserWarning(instruction.Operand, instruction, state);
                    return(false);
                }
                var arrayIdentifier = state.GetIdentifier(Identifier.IdentKind.Normal);
                (var arrayLength, _) = state.Pop();

                var arrayLengthSizeofExp = new SizeofExpression(
                    new Tarray(arrayContentType),
                    SizeofExpression.SizeofExpressionKind.exact,
                    arrayLength);

                var arrayTypeWithPtr = new Tptr(Tptr.PtrKind.Pk_pointer,
                                                new Tarray(arrayContentType));

                var args = new List <Call.CallArg>
                {
                    new Call.CallArg(arrayLengthSizeofExp, arrayTypeWithPtr)
                };

                // Represents memory allocation.
                var callInstr = new Call(returnId: arrayIdentifier,
                                         returnType: arrayTypeWithPtr,
                                         functionExpression: new ConstExpression(
                                             ProcedureName.BuiltIn__new_array),
                                         args: args,
                                         flags: new Call.CallFlags(),
                                         location: state.CurrentLocation);
                var newNode = AddMethodBodyInstructionsToCfg(state, callInstr);
                state.PushExpr(new VarExpression(arrayIdentifier), arrayTypeWithPtr);
                state.PushInstruction(instruction.Next, newNode);
                return(true);

            default:
                return(false);
            }
        }
예제 #2
0
        protected override bool ParseCilInstructionInternal(Instruction instruction,
                                                            ProgramState state)
        {
            switch (instruction.OpCode.Code)
            {
            case Code.Isinst:
                (var objectExpression, var objectType) = state.Pop();
                var typeToCheck               = instruction.Operand as TypeReference;
                var returnIdentifier          = state.GetIdentifier(Identifier.IdentKind.Normal);
                var returnType                = new Tint(Tint.IntKind.IBool, true);
                var builtinFunctionExpression = new ConstExpression(
                    ProcedureName.BuiltIn__instanceof);
                var sizeofExpression = new SizeofExpression(
                    Typ.FromTypeReferenceNoPointer(typeToCheck),
                    SizeofExpression.SizeofExpressionKind.instof);
                var args = new List <Call.CallArg>
                {
                    new Call.CallArg(objectExpression, objectType),
                    new Call.CallArg(sizeofExpression, new Tvoid())
                };
                var callInstruction = new Call(
                    returnIdentifier,
                    returnType,
                    builtinFunctionExpression,
                    args,
                    new Call.CallFlags(),
                    state.CurrentLocation);
                var newNode = AddMethodBodyInstructionsToCfg(state, callInstruction);
                state.PushExpr(new VarExpression(returnIdentifier), returnType);
                state.PushInstruction(instruction.Next, newNode);
                return(true);

            default:
                return(false);
            }
        }
예제 #3
0
 public override object Visit(SizeofExpression node)
 {
     return(0xCCCCCCCCL);           // _evaluationVisitor.Visit( node.Node );
 }
예제 #4
0
 public override void visit_sizeof_expression(SizeofExpression expr)
 {
     expr.accept_children(this);
 }
예제 #5
0
 /// <summary>
 /// Visit operation called for sizeof expressions.
 ///
 /// <param name="expr">a sizeof expression</param>
 /// </summary>
 public virtual void visit_sizeof_expression(SizeofExpression expr)
 {
 }