aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2021-08-31 17:21:33 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2021-09-22 15:40:02 +0200
commit9e4e4272d3f686e750a13d2111b0fb7041db2f4a (patch)
tree288c3421a8da52fcb7e460247f9678fece2ed1c9 /prog
parent169724fe58e8d7d0b4be6f59ca7c1e0f300399e1 (diff)
all: introduce a prog.Call constructor
Create a constructor for the prog.Call type. It allows to reduce the duplication of code now and during further changes.
Diffstat (limited to 'prog')
-rw-r--r--prog/encoding.go7
-rw-r--r--prog/prog.go8
-rw-r--r--prog/rand.go5
3 files changed, 11 insertions, 9 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index b389fc10d..de0e324b1 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -263,11 +263,8 @@ func (p *parser) parseProg() (*Prog, error) {
if meta == nil {
return nil, fmt.Errorf("unknown syscall %v", name)
}
- c := &Call{
- Meta: meta,
- Ret: MakeReturnArg(meta.Ret),
- Comment: p.comment,
- }
+ c := MakeCall(meta, nil)
+ c.Comment = p.comment
prog.Calls = append(prog.Calls, c)
p.Parse('(')
for i := 0; p.Char() != ')'; i++ {
diff --git a/prog/prog.go b/prog/prog.go
index bcc86fb02..576348085 100644
--- a/prog/prog.go
+++ b/prog/prog.go
@@ -20,6 +20,14 @@ type Call struct {
Comment string
}
+func MakeCall(meta *Syscall, args []Arg) *Call {
+ return &Call{
+ Meta: meta,
+ Args: args,
+ Ret: MakeReturnArg(meta.Ret),
+ }
+}
+
type Arg interface {
Type() Type
Dir() Dir
diff --git a/prog/rand.go b/prog/rand.go
index 7ab5068cb..f36cb0822 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -551,10 +551,7 @@ func (r *randGen) generateParticularCall(s *state, meta *Syscall) (calls []*Call
if meta.Attrs.Disabled {
panic(fmt.Sprintf("generating disabled call %v", meta.Name))
}
- c := &Call{
- Meta: meta,
- Ret: MakeReturnArg(meta.Ret),
- }
+ c := MakeCall(meta, nil)
c.Args, calls = r.generateArgs(s, meta.Args, DirIn)
r.target.assignSizesCall(c)
return append(calls, c)