Beispiel #1
0
        public static ConstantPoolInfo Read(ClassReader classReader)
        {
            ushort           tag = classReader.ReadU1();
            ConstantPoolInfo constantPoolInfo = null;

            switch (tag)
            {
            case 7:
                constantPoolInfo = new ConstantClass(); break;

            case 9:
                constantPoolInfo = new ConstantFieldRef(); break;

            case 10:
                constantPoolInfo = new ConstantMethodRef(); break;

            case 11:
                constantPoolInfo = new ConstantInterfaceMethodRef(); break;

            case 8:
                constantPoolInfo = new ConstantString(); break;

            case 3:
                constantPoolInfo = new ConstantInteger(); break;

            case 4:
                constantPoolInfo = new ConstantFloat(); break;

            case 5:
                constantPoolInfo = new ConstantLong(); break;

            case 6:
                constantPoolInfo = new ConstantDouble(); break;

            case 12:
                constantPoolInfo = new ConstantNameAndType(); break;

            case 1:
                constantPoolInfo = new ConstantUtf8(); break;

            case 15:
                constantPoolInfo = new ConstantMethodHandle(); break;

            case 16:
                constantPoolInfo = new ConstantMethodType(); break;

            case 18:
                constantPoolInfo = new ConstantInvokeDynamic(); break;

            default:
                throw new Exception("ClassFileError:constantPoolInfo incorrect");
            }
            constantPoolInfo.Tag = tag;
            constantPoolInfo.ReadConstantPoolInfo(classReader);

            return(constantPoolInfo);
        }
Beispiel #2
0
        public void ExpressionFactoryInt_SuccessfullyCreates_ConstantIntegerExpression_Test()
        {
            //Arrange
            var constantInt = new ConstantInteger <IContext>(1);
            //Act
            var sut = _expressions.Int(1);

            //Assert
            Assert.True(sut.Interpret(_context) == constantInt.Interpret(_context));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var hello  = new CString("My #%d program!\n");
            var one    = new ConstantInteger(1);
            var printf = new FunctionCall(new Label("printf"));

            printf.Arguments.Add(hello);
            printf.Arguments.Add(one);
            var main = new Function("main");

            main.Code.Add(printf);
            var callingConvention = new SysVAbiCallingConvention();
            var ctx = new Context(callingConvention);
            var asm = new Assembly();

            main.Generate(asm, ctx);
            Console.WriteLine(asm);
        }
Beispiel #4
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            switch (NodeType)
            {
            case NodeType.Instruction: sb.Append(Instruction.Name); break;

            case NodeType.FixedIntegerConstant: sb.Append(ConstantInteger.ToString()); break;

            case NodeType.FixedDoubleConstant: sb.Append(ConstantDouble.ToString()); break;

            case NodeType.PhyiscalRegister: sb.Append(PhysicalRegister.ToString()); break;

            case NodeType.VirtualRegister:
            case NodeType.OperandVariable: sb.Append(Alias); break;

            case NodeType.ConstantVariable: sb.Append("(Const "); sb.Append(Alias); sb.Append(")"); break;

            case NodeType.TypeVariable: sb.Append('<'); sb.Append(Alias); sb.Append('>'); break;

            case NodeType.Expression: sb.Append("["); sb.Append(ExpressionNode.ToString()); sb.Append("]"); break;

            case NodeType.Any: sb.Append("_"); break;

            default: break;
            }

            if (ParentNodes.Count != 0)
            {
                foreach (var node in ParentNodes)
                {
                    sb.Append(" ");
                    sb.Append(node.ToString());
                }
            }

            return(sb.ToString());
        }