From 306ca0571c5d906ce76df97bd1ea54f4e0e50240 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 7 Jul 2018 20:07:30 +0200 Subject: prog, pkg/compiler: support fmt type fmt type allows to convert intergers and resources to string representation. --- prog/prog.go | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'prog/prog.go') diff --git a/prog/prog.go b/prog/prog.go index 3474950b9..19db1893d 100644 --- a/prog/prog.go +++ b/prog/prog.go @@ -47,50 +47,31 @@ func (arg *ConstArg) Size() uint64 { } // Value returns value, pid stride and endianness. -func (arg *ConstArg) Value() (uint64, uint64, bool) { +func (arg *ConstArg) Value() (uint64, uint64) { switch typ := (*arg).Type().(type) { case *IntType: - return arg.Val, 0, typ.BigEndian + return arg.Val, 0 case *ConstType: - return arg.Val, 0, typ.BigEndian + return arg.Val, 0 case *FlagsType: - return arg.Val, 0, typ.BigEndian + return arg.Val, 0 case *LenType: - return arg.Val, 0, typ.BigEndian + return arg.Val, 0 case *CsumType: // Checksums are computed dynamically in executor. - return 0, 0, false + return 0, 0 case *ResourceType: - t := typ.Desc.Type.(*IntType) - return arg.Val, 0, t.BigEndian + return arg.Val, 0 case *ProcType: if arg.Val == typ.Default() { - return 0, 0, false + return 0, 0 } - return typ.ValuesStart + arg.Val, typ.ValuesPerProc, typ.BigEndian + return typ.ValuesStart + arg.Val, typ.ValuesPerProc default: panic(fmt.Sprintf("unknown ConstArg type %#v", typ)) } } -func (arg *ConstArg) ValueForProc(pid uint64) uint64 { - v, stride, be := arg.Value() - v += stride * pid - if be { - switch arg.Size() { - case 2: - v = uint64(swap16(uint16(v))) - case 4: - v = uint64(swap32(uint32(v))) - case 8: - v = swap64(v) - default: - panic(fmt.Sprintf("bad const size %v", arg.Size())) - } - } - return v -} - // Used for PtrType and VmaType. type PointerArg struct { ArgCommon -- cgit mrf-deployment