push
github
0 of 3590 new or added lines in 9 files covered. (0.0%)
1384 of 5162 relevant lines covered (26.81%)
5.39 hits per line
| 1 |
package compiler
|
|
| 2 |
|
|
| 3 |
import (
|
|
| 4 |
"encoding/binary"
|
|
| 5 |
) |
|
| 6 |
|
|
|
NEW
|
func Make(op Opcode, operands ...int) Instructions { |
× |
|
NEW
|
def, ok := definitions[op] |
× |
|
NEW
|
if !ok {
|
× |
|
NEW
|
return []byte{} |
× |
|
NEW
|
} |
× |
| 12 |
|
|
|
NEW
|
instructionLen := 1
|
× |
|
NEW
|
for _, w := range def.OperandWidths { |
× |
|
NEW
|
instructionLen += w |
× |
|
NEW
|
} |
× |
| 17 |
|
|
|
NEW
|
instruction := make([]byte, instructionLen) |
× |
|
NEW
|
instruction[0] = byte(op) |
× |
|
NEW
|
|
× |
|
NEW
|
offset := 1
|
× |
|
NEW
|
|
× |
|
NEW
|
for i, o := range operands { |
× |
|
NEW
|
width := def.OperandWidths[i] |
× |
|
NEW
|
switch width {
|
× |
|
NEW
|
case 2: |
× |
|
NEW
|
binary.BigEndian.PutUint16(instruction[offset:], uint16(o))
|
× |
|
NEW
|
case 1: |
× |
|
NEW
|
instruction[offset] = byte(o)
|
× |
| 30 |
} |
|
|
NEW
|
offset += width |
× |
| 32 |
} |
|
| 33 |
|
|
|
NEW
|
return instruction
|
× |
| 35 |
} |