Exemplo n.º 1
0
            public override void Write(JavaWriter wtr)
            {
                Write(wtr, tag, sizeof(ushort));
                ushort constantIndex;

                if (value is int intValue)
                {
                    constantIndex = wtr.ConstInteger(intValue);
                }
                else if (value is float floatValue)
                {
                    constantIndex = wtr.ConstFloat(floatValue);
                }
                else if (value is long longValue)
                {
                    constantIndex = wtr.ConstLong(longValue);
                }
                else if (value is double doubleValue)
                {
                    constantIndex = wtr.ConstDouble(doubleValue);
                }
                else if (value is string stringValue)
                {
                    constantIndex = wtr.ConstString(stringValue);
                }
                else
                {
                    throw wtr.Where.Exception($"invalid constant value");
                }
                wtr.Write16(constantIndex);
            }
Exemplo n.º 2
0
        void FillInstruction_ConstLoad(JavaWriter wtr, Instruction inst)
        {
            int  constantIndex = -1;
            byte op            = 0;

            if (inst.Data is long vLong)
            {
                if (FillInstruction_ConstLoad_Long(inst, vLong))
                {
                    return;
                }
                constantIndex = wtr.ConstLong(vLong);
                op            = 0x14;
            }

            else if (inst.Data is double vDouble)
            {
                if (FillInstruction_ConstLoad_Double(inst, vDouble))
                {
                    return;
                }
                constantIndex = wtr.ConstDouble(vDouble);
                op            = 0x14;
            }

            else
            {
                if (inst.Class != null)
                {
                    if (inst.Data is JavaFieldRef vField)
                    {
                        constantIndex = wtr.ConstField(inst.Class, vField);
                    }

                    else if (inst.Data is JavaMethodRef vMethod)
                    {
                        constantIndex = wtr.ConstMethod(inst.Class, vMethod);
                    }

                    else if (inst.Data == null)
                    {
                        constantIndex = wtr.ConstClass(inst.Class);
                    }
                }

                else if (inst.Data is int vInteger)
                {
                    if (FillInstruction_ConstLoad_Integer(inst, vInteger))
                    {
                        return;
                    }
                    constantIndex = wtr.ConstInteger(vInteger);
                }

                else if (inst.Data is float vFloat)
                {
                    if (FillInstruction_ConstLoad_Float(inst, vFloat))
                    {
                        return;
                    }
                    constantIndex = wtr.ConstFloat(vFloat);
                }

                else if (inst.Data is string vString)
                {
                    constantIndex = wtr.ConstString(vString);
                }

                op          = (byte)((constantIndex <= 255) ? 0x12 : 0x13);
                inst.Opcode = op;
            }

            if (constantIndex == -1)
            {
                throw wtr.Where.Exception("invalid constant in ldc/ldc_w/ldc2_w instruction");
            }

            if (op == 0x12)
            {
                inst.Bytes    = new byte[2];
                inst.Bytes[1] = (byte)constantIndex;
            }
            else
            {
                inst.Bytes    = new byte[3];
                inst.Bytes[1] = (byte)(constantIndex >> 8);
                inst.Bytes[2] = (byte)constantIndex;
            }
            inst.Bytes[0] = op;
        }
Exemplo n.º 3
0
            public override void Write(JavaWriter wtr)
            {
                wtr.Write16(wtr.ConstUtf8(tag));
                wtr.Fork();
                wtr.Write16(methods.Length);
                for (int i = 0; i < methods.Length; i++)
                {
                    wtr.Write16(wtr.ConstMethodHandle(methods[i].mh));
                    var args = methods[i].args;
                    wtr.Write16(args.Length);
                    for (int j = 0; j < args.Length; j++)
                    {
                        ushort constantIndex;
                        var    value = args[j];

                        if (value is int intValue)
                        {
                            constantIndex = wtr.ConstInteger(intValue);
                        }

                        else if (value is float floatValue)
                        {
                            constantIndex = wtr.ConstFloat(floatValue);
                        }

                        else if (value is long longValue)
                        {
                            constantIndex = wtr.ConstLong(longValue);
                        }

                        else if (value is double doubleValue)
                        {
                            constantIndex = wtr.ConstDouble(doubleValue);
                        }

                        else if (value is JavaType classValue)
                        {
                            constantIndex = wtr.ConstClass(classValue);
                        }

                        else if (value is string stringValue)
                        {
                            constantIndex = wtr.ConstString(stringValue);
                        }

                        else if (value is JavaMethodHandle methodHandleValue)
                        {
                            constantIndex = wtr.ConstMethodHandle(methodHandleValue);
                        }

                        else if (value is JavaMethodType methodTypeValue)
                        {
                            constantIndex = wtr.ConstMethodType(methodTypeValue);
                        }
                        else
                        {
                            throw wtr.Where.Exception($"invalid constant value");
                        }

                        wtr.Write16(constantIndex);
                    }
                }
                wtr.Join();
            }