• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

unpackdev / solgo / 8960975808

05 May 2024 08:34PM UTC coverage: 64.769% (-0.3%) from 65.065%
8960975808

push

github

web-flow
Opcode functions and instruction tree + JSON normalization (#210)

245 of 449 new or added lines in 61 files covered. (54.57%)

2 existing lines in 1 file now uncovered.

27471 of 42414 relevant lines covered (64.77%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/opcode/instruction_tree.go
1
package opcode
2

3
import "errors"
4

5
type InstructionTree struct {
6
        Instruction Instruction
7
        Children    []*InstructionTree
8
}
9

NEW
10
func NewInstructionTree(instruction Instruction) *InstructionTree {
×
NEW
11
        return &InstructionTree{
×
NEW
12
                Instruction: instruction,
×
NEW
13
                Children:    []*InstructionTree{},
×
NEW
14
        }
×
NEW
15
}
×
16

17
// Function to recursively build the instruction tree
NEW
18
func buildInstructionTree(instructions []Instruction, offset int) (*InstructionTree, int, error) {
×
NEW
19
        // Check if offset is out of range
×
NEW
20
        if offset < 0 || offset >= len(instructions) {
×
NEW
21
                return nil, offset, errors.New("offset out of range")
×
NEW
22
        }
×
23

NEW
24
        root := NewInstructionTree(instructions[offset])
×
NEW
25

×
NEW
26
        // Start from the next instruction after the root
×
NEW
27
        nextOffset := offset + 1
×
NEW
28

×
NEW
29
        // Iterate through the instructions to find child nodes
×
NEW
30
        for nextOffset < len(instructions) {
×
NEW
31
                inst := instructions[nextOffset]
×
NEW
32
                if isChildOf(root.Instruction, inst) {
×
NEW
33
                        child, newOffset, err := buildInstructionTree(instructions, nextOffset)
×
NEW
34
                        if err != nil {
×
NEW
35
                                return nil, offset, err
×
NEW
36
                        }
×
NEW
37
                        root.Children = append(root.Children, child)
×
NEW
38
                        nextOffset = newOffset
×
NEW
39
                } else {
×
NEW
40
                        break
×
41
                }
42
        }
43

NEW
44
        return root, nextOffset, nil
×
45
}
46

47
// Function to determine if an instruction is a child of another instruction
NEW
48
func isChildOf(parent, child Instruction) bool {
×
NEW
49
        // Check if the child instruction's offset is greater than the parent instruction's offset
×
NEW
50
        if child.Offset <= parent.Offset {
×
NEW
51
                return false
×
NEW
52
        }
×
53

54
        // Check if the child instruction's offset falls within the range of the parent instruction
NEW
55
        if child.Offset >= parent.Offset && child.Offset < parent.Offset+len(parent.Args) {
×
NEW
56
                return true
×
NEW
57
        }
×
58

59
        // Check if the child instruction occurs within a basic block following the parent instruction
NEW
60
        for _, opcode := range controlFlowOpcodes {
×
NEW
61
                if child.OpCode == opcode {
×
NEW
62
                        return true
×
NEW
63
                }
×
64
        }
65

NEW
66
        return false
×
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc