How to use validate method of prog Package

Best Syzkaller code snippet using prog.validate

obj.go

Source:obj.go Github

copy

Full Screen

...767 }768 }769 // Validate all instructions - this provides nice error messages.770 for p := cursym.Func.Text; p != nil; p = p.Link {771 encodingForProg(p).validate(p)772 }773}774// signExtend sign extends val starting at bit bit.775func signExtend(val int64, bit uint) int64 {776 return val << (64 - bit) >> (64 - bit)777}778// Split32BitImmediate splits a signed 32-bit immediate into a signed 20-bit779// upper immediate and a signed 12-bit lower immediate to be added to the upper780// result. For example, high may be used in LUI and low in a following ADDI to781// generate a full 32-bit constant.782func Split32BitImmediate(imm int64) (low, high int64, err error) {783 if !immIFits(imm, 32) {784 return 0, 0, fmt.Errorf("immediate does not fit in 32-bits: %d", imm)785 }786 // Nothing special needs to be done if the immediate fits in 12-bits.787 if immIFits(imm, 12) {788 return imm, 0, nil789 }790 high = imm >> 12791 // The bottom 12 bits will be treated as signed.792 //793 // If that will result in a negative 12 bit number, add 1 to794 // our upper bits to adjust for the borrow.795 //796 // It is not possible for this increment to overflow. To797 // overflow, the 20 top bits would be 1, and the sign bit for798 // the low 12 bits would be set, in which case the entire 32799 // bit pattern fits in a 12 bit signed value.800 if imm&(1<<11) != 0 {801 high++802 }803 low = signExtend(imm, 12)804 high = signExtend(high, 20)805 return low, high, nil806}807func regVal(r, min, max int16) uint32 {808 if r < min || r > max {809 panic(fmt.Sprintf("register out of range, want %d < %d < %d", min, r, max))810 }811 return uint32(r - min)812}813// regI returns an integer register.814func regI(r int16) uint32 {815 return regVal(r, REG_X0, REG_X31)816}817// regF returns a float register.818func regF(r int16) uint32 {819 return regVal(r, REG_F0, REG_F31)820}821// regAddr extracts a register from an Addr.822func regAddr(a obj.Addr, min, max int16) uint32 {823 if a.Type != obj.TYPE_REG {824 panic(fmt.Sprintf("ill typed: %+v", a))825 }826 return regVal(a.Reg, min, max)827}828// regIAddr extracts the integer register from an Addr.829func regIAddr(a obj.Addr) uint32 {830 return regAddr(a, REG_X0, REG_X31)831}832// regFAddr extracts the float register from an Addr.833func regFAddr(a obj.Addr) uint32 {834 return regAddr(a, REG_F0, REG_F31)835}836// immIFits reports whether immediate value x fits in nbits bits837// as a signed integer.838func immIFits(x int64, nbits uint) bool {839 nbits--840 var min int64 = -1 << nbits841 var max int64 = 1<<nbits - 1842 return min <= x && x <= max843}844// immUFits reports whether immediate value x fits in nbits bits845// as an unsigned integer.846func immUFits(x int64, nbits uint) bool {847 var max int64 = 1<<nbits - 1848 return 0 <= x && x <= max849}850// immI extracts the signed integer literal of the specified size from an Addr.851func immI(a obj.Addr, nbits uint) uint32 {852 if a.Type != obj.TYPE_CONST {853 panic(fmt.Sprintf("ill typed: %+v", a))854 }855 if !immIFits(a.Offset, nbits) {856 panic(fmt.Sprintf("signed immediate %d in %v cannot fit in %d bits", a.Offset, a, nbits))857 }858 return uint32(a.Offset)859}860// immU extracts the unsigned integer literal of the specified size from an Addr.861func immU(a obj.Addr, nbits uint) uint32 {862 if a.Type != obj.TYPE_CONST {863 panic(fmt.Sprintf("ill typed: %+v", a))864 }865 if !immUFits(a.Offset, nbits) {866 panic(fmt.Sprintf("unsigned immediate %d in %v cannot fit in %d bits", a.Offset, a, nbits))867 }868 return uint32(a.Offset)869}870func wantImmI(p *obj.Prog, pos string, a obj.Addr, nbits uint) {871 if a.Type != obj.TYPE_CONST {872 p.Ctxt.Diag("%v\texpected immediate in %s position but got %s", p, pos, obj.Dconv(p, &a))873 return874 }875 if !immIFits(a.Offset, nbits) {876 p.Ctxt.Diag("%v\tsigned immediate in %s position cannot be larger than %d bits but got %d", p, pos, nbits, a.Offset)877 }878}879func wantImmU(p *obj.Prog, pos string, a obj.Addr, nbits uint) {880 if a.Type != obj.TYPE_CONST {881 p.Ctxt.Diag("%v\texpected immediate in %s position but got %s", p, pos, obj.Dconv(p, &a))882 return883 }884 if !immUFits(a.Offset, nbits) {885 p.Ctxt.Diag("%v\tunsigned immediate in %s position cannot be larger than %d bits but got %d", p, pos, nbits, a.Offset)886 }887}888func wantReg(p *obj.Prog, pos string, descr string, r, min, max int16) {889 if r < min || r > max {890 p.Ctxt.Diag("%v\texpected %s register in %s position but got non-%s register %s", p, descr, pos, descr, regName(int(r)))891 }892}893// wantIntReg checks that r is an integer register.894func wantIntReg(p *obj.Prog, pos string, r int16) {895 wantReg(p, pos, "integer", r, REG_X0, REG_X31)896}897// wantFloatReg checks that r is a floating-point register.898func wantFloatReg(p *obj.Prog, pos string, r int16) {899 wantReg(p, pos, "float", r, REG_F0, REG_F31)900}901func wantRegAddr(p *obj.Prog, pos string, a *obj.Addr, descr string, min int16, max int16) {902 if a == nil {903 p.Ctxt.Diag("%v\texpected register in %s position but got nothing", p, pos)904 return905 }906 if a.Type != obj.TYPE_REG {907 p.Ctxt.Diag("%v\texpected register in %s position but got %s", p, pos, obj.Dconv(p, a))908 return909 }910 if a.Reg < min || a.Reg > max {911 p.Ctxt.Diag("%v\texpected %s register in %s position but got non-%s register %s", p, descr, pos, descr, obj.Dconv(p, a))912 }913}914// wantIntRegAddr checks that a contains an integer register.915func wantIntRegAddr(p *obj.Prog, pos string, a *obj.Addr) {916 wantRegAddr(p, pos, a, "integer", REG_X0, REG_X31)917}918// wantFloatRegAddr checks that a contains a floating-point register.919func wantFloatRegAddr(p *obj.Prog, pos string, a *obj.Addr) {920 wantRegAddr(p, pos, a, "float", REG_F0, REG_F31)921}922// wantEvenJumpOffset checks that the jump offset is a multiple of two.923func wantEvenJumpOffset(p *obj.Prog) {924 if p.To.Offset%1 != 0 {925 p.Ctxt.Diag("%v\tjump offset %v must be even", p, obj.Dconv(p, &p.To))926 }927}928func validateRIII(p *obj.Prog) {929 wantIntRegAddr(p, "from", &p.From)930 wantIntReg(p, "reg", p.Reg)931 wantIntRegAddr(p, "to", &p.To)932}933func validateRFFF(p *obj.Prog) {934 wantFloatRegAddr(p, "from", &p.From)935 wantFloatReg(p, "reg", p.Reg)936 wantFloatRegAddr(p, "to", &p.To)937}938func validateRFFI(p *obj.Prog) {939 wantFloatRegAddr(p, "from", &p.From)940 wantFloatReg(p, "reg", p.Reg)941 wantIntRegAddr(p, "to", &p.To)942}943func validateRFI(p *obj.Prog) {944 wantFloatRegAddr(p, "from", &p.From)945 wantIntRegAddr(p, "to", &p.To)946}947func validateRIF(p *obj.Prog) {948 wantIntRegAddr(p, "from", &p.From)949 wantFloatRegAddr(p, "to", &p.To)950}951func validateRFF(p *obj.Prog) {952 wantFloatRegAddr(p, "from", &p.From)953 wantFloatRegAddr(p, "to", &p.To)954}955func validateII(p *obj.Prog) {956 wantImmI(p, "from", p.From, 12)957 wantIntReg(p, "reg", p.Reg)958 wantIntRegAddr(p, "to", &p.To)959}960func validateIF(p *obj.Prog) {961 wantImmI(p, "from", p.From, 12)962 wantIntReg(p, "reg", p.Reg)963 wantFloatRegAddr(p, "to", &p.To)964}965func validateSI(p *obj.Prog) {966 wantImmI(p, "from", p.From, 12)967 wantIntReg(p, "reg", p.Reg)968 wantIntRegAddr(p, "to", &p.To)969}970func validateSF(p *obj.Prog) {971 wantImmI(p, "from", p.From, 12)972 wantFloatReg(p, "reg", p.Reg)973 wantIntRegAddr(p, "to", &p.To)974}975func validateB(p *obj.Prog) {976 // Offsets are multiples of two, so accept 13 bit immediates for the977 // 12 bit slot. We implicitly drop the least significant bit in encodeB.978 wantEvenJumpOffset(p)979 wantImmI(p, "to", p.To, 13)980 wantIntReg(p, "reg", p.Reg)981 wantIntRegAddr(p, "from", &p.From)982}983func validateU(p *obj.Prog) {984 if p.As == AAUIPC && p.Mark&(NEED_PCREL_ITYPE_RELOC|NEED_PCREL_STYPE_RELOC) != 0 {985 // TODO(sorear): Hack. The Offset is being used here to temporarily986 // store the relocation addend, not as an actual offset to assemble,987 // so it's OK for it to be out of range. Is there a more valid way988 // to represent this state?989 return990 }991 wantImmU(p, "from", p.From, 20)992 wantIntRegAddr(p, "to", &p.To)993}994func validateJ(p *obj.Prog) {995 // Offsets are multiples of two, so accept 21 bit immediates for the996 // 20 bit slot. We implicitly drop the least significant bit in encodeJ.997 wantEvenJumpOffset(p)998 wantImmI(p, "to", p.To, 21)999 wantIntRegAddr(p, "from", &p.From)1000}1001func validateRaw(p *obj.Prog) {1002 // Treat the raw value specially as a 32-bit unsigned integer.1003 // Nobody wants to enter negative machine code.1004 a := p.From1005 if a.Type != obj.TYPE_CONST {1006 p.Ctxt.Diag("%v\texpected immediate in raw position but got %s", p, obj.Dconv(p, &a))1007 return1008 }1009 if a.Offset < 0 || 1<<32 <= a.Offset {1010 p.Ctxt.Diag("%v\timmediate in raw position cannot be larger than 32 bits but got %d", p, a.Offset)1011 }1012}1013// encodeR encodes an R-type RISC-V instruction.1014func encodeR(p *obj.Prog, rs1 uint32, rs2 uint32, rd uint32) uint32 {1015 ins := encode(p.As)1016 if ins == nil {1017 panic("encodeR: could not encode instruction")1018 }1019 if ins.rs2 != 0 && rs2 != 0 {1020 panic("encodeR: instruction uses rs2, but rs2 was nonzero")1021 }1022 // Use Scond for the floating-point rounding mode override.1023 // TODO(sorear): Is there a more appropriate way to handle opcode extension bits like this?1024 return ins.funct7<<25 | ins.rs2<<20 | rs2<<20 | rs1<<15 | ins.funct3<<12 | uint32(p.Scond)<<12 | rd<<7 | ins.opcode1025}1026func encodeRIII(p *obj.Prog) uint32 {1027 return encodeR(p, regI(p.Reg), regIAddr(p.From), regIAddr(p.To))1028}1029func encodeRFFF(p *obj.Prog) uint32 {1030 return encodeR(p, regF(p.Reg), regFAddr(p.From), regFAddr(p.To))1031}1032func encodeRFFI(p *obj.Prog) uint32 {1033 return encodeR(p, regF(p.Reg), regFAddr(p.From), regIAddr(p.To))1034}1035func encodeRFI(p *obj.Prog) uint32 {1036 return encodeR(p, regFAddr(p.From), 0, regIAddr(p.To))1037}1038func encodeRIF(p *obj.Prog) uint32 {1039 return encodeR(p, regIAddr(p.From), 0, regFAddr(p.To))1040}1041func encodeRFF(p *obj.Prog) uint32 {1042 return encodeR(p, regFAddr(p.From), 0, regFAddr(p.To))1043}1044// encodeI encodes an I-type RISC-V instruction.1045func encodeI(p *obj.Prog, rd uint32) uint32 {1046 imm := immI(p.From, 12)1047 rs1 := regI(p.Reg)1048 ins := encode(p.As)1049 if ins == nil {1050 panic("encodeI: could not encode instruction")1051 }1052 imm |= uint32(ins.csr)1053 return imm<<20 | rs1<<15 | ins.funct3<<12 | rd<<7 | ins.opcode1054}1055func encodeII(p *obj.Prog) uint32 {1056 return encodeI(p, regIAddr(p.To))1057}1058func encodeIF(p *obj.Prog) uint32 {1059 return encodeI(p, regFAddr(p.To))1060}1061// encodeS encodes an S-type RISC-V instruction.1062func encodeS(p *obj.Prog, rs2 uint32) uint32 {1063 imm := immI(p.From, 12)1064 rs1 := regIAddr(p.To)1065 ins := encode(p.As)1066 if ins == nil {1067 panic("encodeS: could not encode instruction")1068 }1069 return (imm>>5)<<25 | rs2<<20 | rs1<<15 | ins.funct3<<12 | (imm&0x1f)<<7 | ins.opcode1070}1071func encodeSI(p *obj.Prog) uint32 {1072 return encodeS(p, regI(p.Reg))1073}1074func encodeSF(p *obj.Prog) uint32 {1075 return encodeS(p, regF(p.Reg))1076}1077// encodeB encodes a B-type RISC-V instruction.1078func encodeB(p *obj.Prog) uint32 {1079 imm := immI(p.To, 13)1080 rs2 := regI(p.Reg)1081 rs1 := regIAddr(p.From)1082 ins := encode(p.As)1083 if ins == nil {1084 panic("encodeB: could not encode instruction")1085 }1086 return (imm>>12)<<31 | ((imm>>5)&0x3f)<<25 | rs2<<20 | rs1<<15 | ins.funct3<<12 | ((imm>>1)&0xf)<<8 | ((imm>>11)&0x1)<<7 | ins.opcode1087}1088// encodeU encodes a U-type RISC-V instruction.1089func encodeU(p *obj.Prog) uint32 {1090 // The immediates for encodeU are the upper 20 bits of a 32 bit value.1091 // Rather than have the user/compiler generate a 32 bit constant, the1092 // bottommost bits of which must all be zero, instead accept just the1093 // top bits.1094 imm := immU(p.From, 20)1095 rd := regIAddr(p.To)1096 ins := encode(p.As)1097 if ins == nil {1098 panic("encodeU: could not encode instruction")1099 }1100 return imm<<12 | rd<<7 | ins.opcode1101}1102// encodeJ encodes a J-type RISC-V instruction.1103func encodeJ(p *obj.Prog) uint32 {1104 imm := immI(p.To, 21)1105 rd := regIAddr(p.From)1106 ins := encode(p.As)1107 if ins == nil {1108 panic("encodeJ: could not encode instruction")1109 }1110 return (imm>>20)<<31 | ((imm>>1)&0x3ff)<<21 | ((imm>>11)&0x1)<<20 | ((imm>>12)&0xff)<<12 | rd<<7 | ins.opcode1111}1112// encodeRaw encodes a raw instruction value.1113func encodeRaw(p *obj.Prog) uint32 {1114 // Treat the raw value specially as a 32-bit unsigned integer.1115 // Nobody wants to enter negative machine code.1116 a := p.From1117 if a.Type != obj.TYPE_CONST {1118 panic(fmt.Sprintf("ill typed: %+v", a))1119 }1120 if a.Offset < 0 || 1<<32 <= a.Offset {1121 panic(fmt.Sprintf("immediate %d in %v cannot fit in 32 bits", a.Offset, a))1122 }1123 return uint32(a.Offset)1124}1125func EncodeIImmediate(imm int64) (int64, error) {1126 if !immIFits(imm, 12) {1127 return 0, fmt.Errorf("immediate %#x does not fit in 12 bits", imm)1128 }1129 return imm << 20, nil1130}1131func EncodeSImmediate(imm int64) (int64, error) {1132 if !immIFits(imm, 12) {1133 return 0, fmt.Errorf("immediate %#x does not fit in 12 bits", imm)1134 }1135 return ((imm >> 5) << 25) | ((imm & 0x1f) << 7), nil1136}1137func EncodeUImmediate(imm int64) (int64, error) {1138 if !immUFits(imm, 20) {1139 return 0, fmt.Errorf("immediate %#x does not fit in 20 bits", imm)1140 }1141 return imm << 12, nil1142}1143type encoding struct {1144 encode func(*obj.Prog) uint32 // encode returns the machine code for an *obj.Prog1145 validate func(*obj.Prog) // validate validates an *obj.Prog, calling ctxt.Diag for any issues1146 length int // length of encoded instruction; 0 for pseudo-ops, 4 otherwise1147}1148var (1149 // Encodings have the following naming convention:1150 //1151 // 1. the instruction encoding (R/I/S/B/U/J), in lowercase1152 // 2. zero or more register operand identifiers (I = integer1153 // register, F = float register), in uppercase1154 // 3. the word "Encoding"1155 //1156 // For example, rIIIEncoding indicates an R-type instruction with two1157 // integer register inputs and an integer register output; sFEncoding1158 // indicates an S-type instruction with rs2 being a float register.1159 rIIIEncoding = encoding{encode: encodeRIII, validate: validateRIII, length: 4}1160 rFFFEncoding = encoding{encode: encodeRFFF, validate: validateRFFF, length: 4}1161 rFFIEncoding = encoding{encode: encodeRFFI, validate: validateRFFI, length: 4}1162 rFIEncoding = encoding{encode: encodeRFI, validate: validateRFI, length: 4}1163 rIFEncoding = encoding{encode: encodeRIF, validate: validateRIF, length: 4}1164 rFFEncoding = encoding{encode: encodeRFF, validate: validateRFF, length: 4}1165 iIEncoding = encoding{encode: encodeII, validate: validateII, length: 4}1166 iFEncoding = encoding{encode: encodeIF, validate: validateIF, length: 4}1167 sIEncoding = encoding{encode: encodeSI, validate: validateSI, length: 4}1168 sFEncoding = encoding{encode: encodeSF, validate: validateSF, length: 4}1169 bEncoding = encoding{encode: encodeB, validate: validateB, length: 4}1170 uEncoding = encoding{encode: encodeU, validate: validateU, length: 4}1171 jEncoding = encoding{encode: encodeJ, validate: validateJ, length: 4}1172 // rawEncoding encodes a raw instruction byte sequence.1173 rawEncoding = encoding{encode: encodeRaw, validate: validateRaw, length: 4}1174 // pseudoOpEncoding panics if encoding is attempted, but does no validation.1175 pseudoOpEncoding = encoding{encode: nil, validate: func(*obj.Prog) {}, length: 0}1176 // badEncoding is used when an invalid op is encountered.1177 // An error has already been generated, so let anything else through.1178 badEncoding = encoding{encode: func(*obj.Prog) uint32 { return 0 }, validate: func(*obj.Prog) {}, length: 0}1179)1180// encodingForAs contains the encoding for a RISC-V instruction.1181// Instructions are masked with obj.AMask to keep indices small.1182var encodingForAs = [ALAST & obj.AMask]encoding{1183 // Unprivileged ISA1184 // 2.4: Integer Computational Instructions1185 AADDI & obj.AMask: iIEncoding,1186 ASLTI & obj.AMask: iIEncoding,1187 ASLTIU & obj.AMask: iIEncoding,1188 AANDI & obj.AMask: iIEncoding,1189 AORI & obj.AMask: iIEncoding,1190 AXORI & obj.AMask: iIEncoding,1191 ASLLI & obj.AMask: iIEncoding,1192 ASRLI & obj.AMask: iIEncoding,1193 ASRAI & obj.AMask: iIEncoding,1194 ALUI & obj.AMask: uEncoding,1195 AAUIPC & obj.AMask: uEncoding,1196 AADD & obj.AMask: rIIIEncoding,1197 ASLT & obj.AMask: rIIIEncoding,1198 ASLTU & obj.AMask: rIIIEncoding,1199 AAND & obj.AMask: rIIIEncoding,1200 AOR & obj.AMask: rIIIEncoding,1201 AXOR & obj.AMask: rIIIEncoding,1202 ASLL & obj.AMask: rIIIEncoding,1203 ASRL & obj.AMask: rIIIEncoding,1204 ASUB & obj.AMask: rIIIEncoding,1205 ASRA & obj.AMask: rIIIEncoding,1206 // 2.5: Control Transfer Instructions1207 AJAL & obj.AMask: jEncoding,1208 AJALR & obj.AMask: iIEncoding,1209 ABEQ & obj.AMask: bEncoding,1210 ABNE & obj.AMask: bEncoding,1211 ABLT & obj.AMask: bEncoding,1212 ABLTU & obj.AMask: bEncoding,1213 ABGE & obj.AMask: bEncoding,1214 ABGEU & obj.AMask: bEncoding,1215 // 2.6: Load and Store Instructions1216 ALW & obj.AMask: iIEncoding,1217 ALWU & obj.AMask: iIEncoding,1218 ALH & obj.AMask: iIEncoding,1219 ALHU & obj.AMask: iIEncoding,1220 ALB & obj.AMask: iIEncoding,1221 ALBU & obj.AMask: iIEncoding,1222 ASW & obj.AMask: sIEncoding,1223 ASH & obj.AMask: sIEncoding,1224 ASB & obj.AMask: sIEncoding,1225 // 5.2: Integer Computational Instructions (RV64I)1226 AADDIW & obj.AMask: iIEncoding,1227 ASLLIW & obj.AMask: iIEncoding,1228 ASRLIW & obj.AMask: iIEncoding,1229 ASRAIW & obj.AMask: iIEncoding,1230 AADDW & obj.AMask: rIIIEncoding,1231 ASLLW & obj.AMask: rIIIEncoding,1232 ASRLW & obj.AMask: rIIIEncoding,1233 ASUBW & obj.AMask: rIIIEncoding,1234 ASRAW & obj.AMask: rIIIEncoding,1235 // 5.3: Load and Store Instructions (RV64I)1236 ALD & obj.AMask: iIEncoding,1237 ASD & obj.AMask: sIEncoding,1238 // 7.1: Multiplication Operations1239 AMUL & obj.AMask: rIIIEncoding,1240 AMULH & obj.AMask: rIIIEncoding,1241 AMULHU & obj.AMask: rIIIEncoding,1242 AMULHSU & obj.AMask: rIIIEncoding,1243 AMULW & obj.AMask: rIIIEncoding,1244 ADIV & obj.AMask: rIIIEncoding,1245 ADIVU & obj.AMask: rIIIEncoding,1246 AREM & obj.AMask: rIIIEncoding,1247 AREMU & obj.AMask: rIIIEncoding,1248 ADIVW & obj.AMask: rIIIEncoding,1249 ADIVUW & obj.AMask: rIIIEncoding,1250 AREMW & obj.AMask: rIIIEncoding,1251 AREMUW & obj.AMask: rIIIEncoding,1252 // 10.1: Base Counters and Timers1253 ARDCYCLE & obj.AMask: iIEncoding,1254 ARDTIME & obj.AMask: iIEncoding,1255 ARDINSTRET & obj.AMask: iIEncoding,1256 // 11.5: Single-Precision Load and Store Instructions1257 AFLW & obj.AMask: iFEncoding,1258 AFSW & obj.AMask: sFEncoding,1259 // 11.6: Single-Precision Floating-Point Computational Instructions1260 AFADDS & obj.AMask: rFFFEncoding,1261 AFSUBS & obj.AMask: rFFFEncoding,1262 AFMULS & obj.AMask: rFFFEncoding,1263 AFDIVS & obj.AMask: rFFFEncoding,1264 AFMINS & obj.AMask: rFFFEncoding,1265 AFMAXS & obj.AMask: rFFFEncoding,1266 AFSQRTS & obj.AMask: rFFFEncoding,1267 // 11.7: Single-Precision Floating-Point Conversion and Move Instructions1268 AFCVTWS & obj.AMask: rFIEncoding,1269 AFCVTLS & obj.AMask: rFIEncoding,1270 AFCVTSW & obj.AMask: rIFEncoding,1271 AFCVTSL & obj.AMask: rIFEncoding,1272 AFCVTWUS & obj.AMask: rFIEncoding,1273 AFCVTLUS & obj.AMask: rFIEncoding,1274 AFCVTSWU & obj.AMask: rIFEncoding,1275 AFCVTSLU & obj.AMask: rIFEncoding,1276 AFSGNJS & obj.AMask: rFFFEncoding,1277 AFSGNJNS & obj.AMask: rFFFEncoding,1278 AFSGNJXS & obj.AMask: rFFFEncoding,1279 AFMVXS & obj.AMask: rFIEncoding,1280 AFMVSX & obj.AMask: rIFEncoding,1281 AFMVXW & obj.AMask: rFIEncoding,1282 AFMVWX & obj.AMask: rIFEncoding,1283 // 11.8: Single-Precision Floating-Point Compare Instructions1284 AFEQS & obj.AMask: rFFIEncoding,1285 AFLTS & obj.AMask: rFFIEncoding,1286 AFLES & obj.AMask: rFFIEncoding,1287 // 12.3: Double-Precision Load and Store Instructions1288 AFLD & obj.AMask: iFEncoding,1289 AFSD & obj.AMask: sFEncoding,1290 // 12.4: Double-Precision Floating-Point Computational Instructions1291 AFADDD & obj.AMask: rFFFEncoding,1292 AFSUBD & obj.AMask: rFFFEncoding,1293 AFMULD & obj.AMask: rFFFEncoding,1294 AFDIVD & obj.AMask: rFFFEncoding,1295 AFMIND & obj.AMask: rFFFEncoding,1296 AFMAXD & obj.AMask: rFFFEncoding,1297 AFSQRTD & obj.AMask: rFFFEncoding,1298 // 12.5: Double-Precision Floating-Point Conversion and Move Instructions1299 AFCVTWD & obj.AMask: rFIEncoding,1300 AFCVTLD & obj.AMask: rFIEncoding,1301 AFCVTDW & obj.AMask: rIFEncoding,1302 AFCVTDL & obj.AMask: rIFEncoding,1303 AFCVTWUD & obj.AMask: rFIEncoding,1304 AFCVTLUD & obj.AMask: rFIEncoding,1305 AFCVTDWU & obj.AMask: rIFEncoding,1306 AFCVTDLU & obj.AMask: rIFEncoding,1307 AFCVTSD & obj.AMask: rFFEncoding,1308 AFCVTDS & obj.AMask: rFFEncoding,1309 AFSGNJD & obj.AMask: rFFFEncoding,1310 AFSGNJND & obj.AMask: rFFFEncoding,1311 AFSGNJXD & obj.AMask: rFFFEncoding,1312 AFMVXD & obj.AMask: rFIEncoding,1313 AFMVDX & obj.AMask: rIFEncoding,1314 // 12.6: Double-Precision Floating-Point Compare Instructions1315 AFEQD & obj.AMask: rFFIEncoding,1316 AFLTD & obj.AMask: rFFIEncoding,1317 AFLED & obj.AMask: rFFIEncoding,1318 // Privileged ISA1319 // 3.2.1: Environment Call and Breakpoint1320 AECALL & obj.AMask: iIEncoding,1321 AEBREAK & obj.AMask: iIEncoding,1322 // Escape hatch1323 AWORD & obj.AMask: rawEncoding,1324 // Pseudo-operations1325 obj.AFUNCDATA: pseudoOpEncoding,1326 obj.APCDATA: pseudoOpEncoding,1327 obj.ATEXT: pseudoOpEncoding,1328 obj.ANOP: pseudoOpEncoding,1329}1330// encodingForProg returns the encoding (encode+validate funcs) for an *obj.Prog.1331func encodingForProg(p *obj.Prog) encoding {1332 if base := p.As &^ obj.AMask; base != obj.ABaseRISCV && base != 0 {1333 p.Ctxt.Diag("encodingForProg: not a RISC-V instruction %s", p.As)1334 return badEncoding1335 }1336 as := p.As & obj.AMask1337 if int(as) >= len(encodingForAs) {1338 p.Ctxt.Diag("encodingForProg: bad RISC-V instruction %s", p.As)1339 return badEncoding1340 }1341 enc := encodingForAs[as]1342 if enc.validate == nil {1343 p.Ctxt.Diag("encodingForProg: no encoding for instruction %s", p.As)1344 return badEncoding1345 }1346 return enc1347}1348// assemble emits machine code.1349// It is called at the very end of the assembly process.1350func assemble(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {1351 var symcode []uint321352 for p := cursym.Func.Text; p != nil; p = p.Link {1353 switch p.As {1354 case AJALR:1355 if p.To.Sym != nil {1356 // This is a CALL/JMP. We add a relocation only...

Full Screen

Full Screen

programmer.go

Source:programmer.go Github

copy

Full Screen

...18 jwt "github.com/form3tech-oss/jwt-go"19)20type Programmer struct {21 Id int `json:"id"`22 Name string `json:"name" validate:"required"`23 Email string `json:"email" validate:"required,email"`24 Password string `json:"password,omitempty"`25 Role string `json:"role" validate:"required"`26}27func (prog Programmer) ValidateStruct() map[string]string {28 validate := validator.New()29 err := validate.Struct(prog)30 if err != nil {31 return utils.ParseValidator(err.(validator.ValidationErrors))32 }33 return nil34}35func GetProgrammer(c *fiber.Ctx) error {36 conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))37 if err != nil {38 fmt.Println(err.Error())39 return fiber.NewError(500, "Cannot connect to the database!")40 }41 defer conn.Close(context.Background());42 rows, err := conn.Query(context.Background(), "select id, name, email, role from programmer where id <> 1")43 if err != nil {...

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter a number")4 fmt.Scan(&a)5 prog.Validate(a)6}

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p := prog{val: 10}4 p.validate()5}6import "fmt"7func main() {8 p := prog{val: 10}9 p.validate()10}11import "fmt"12func main() {13 p := prog{val: 10}14 p.validate()15}16import "fmt"17func main() {18 p := prog{val: 10}19 p.validate()20}21import "fmt"22func main() {23 p := prog{val: 10}24 p.validate()25}26import "fmt"27func main() {28 p := prog{val: 10}29 p.validate()30}31import "fmt"32func main() {33 p := prog{val: 10}34 p.validate()35}36import "fmt"37func main() {38 p := prog{val: 10}39 p.validate()40}41import "fmt"42func main() {43 p := prog{val: 10}44 p.validate()45}46import "fmt"47func main() {48 p := prog{val: 10}49 p.validate()50}51import "fmt"52func main() {53 p := prog{val: 10}54 p.validate()55}56import "fmt"57func main() {58 p := prog{val: 10}59 p.validate()

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the number to be validated")4 fmt.Scanln(&num)5 if prog.Validate(num) {6 fmt.Println("The number is valid")7 } else {8 fmt.Println("The number is invalid")9 }10}

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter a number")4 fmt.Scanf("%d", &a)5 prog := Prog{a}6 prog.Validate()7}

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4 prog.Validate()5}6import "fmt"7func Validate() {8 fmt.Println("I am in prog class")9}10The import path is the location of the package in the repository. For example, the import path for the fmt package is fmt. The

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "path/to/Prog"3func main() {4 p := Prog.Prog{}5 if p.Validate() {6 fmt.Println("The program is valid")7 } else {8 fmt.Println("The program is invalid")9 }10}

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(prog.Validate("sdf"))4}5func Validate(str string) bool {6}7import (8func main() {9 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {10 fmt.Fprintf(w, "Hello, you've requested: %s11 })12 http.ListenAndServe(":8080", nil)13}14import (15func main() {16 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {17 fmt.Fprintf(w, "Hello, you've requested: %s18 })19 http.ListenAndServe(":8080", nil)20}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful