* * Instruction list into bytecode functions */
(wordList []Word)
| 360 | * Instruction list into bytecode functions |
| 361 | */ |
| 362 | func encodeInstructionListToBytecode(wordList []Word) ([]*f.Element, uint8, error) { |
| 363 | n := len(wordList) |
| 364 | bytecodes := make([]*f.Element, 0, n+(n/2)+1) |
| 365 | var total_size uint8 |
| 366 | for i, word := range wordList { |
| 367 | switch w := word.(type) { |
| 368 | case Instruction: |
| 369 | total_size += w.Size() |
| 370 | bytecode, err := encodeOneInstruction(&w) |
| 371 | if err != nil { |
| 372 | return nil, 0, err |
| 373 | } |
| 374 | bytecodes = append(bytecodes, bytecode) |
| 375 | |
| 376 | case Immediate: |
| 377 | imm, err := new(f.Element).SetString(w) |
| 378 | if err != nil { |
| 379 | return nil, 0, err |
| 380 | } |
| 381 | bytecodes = append(bytecodes, imm) |
| 382 | |
| 383 | default: |
| 384 | return nil, 0, fmt.Errorf("word %d is not an instruction or immediate", i) |
| 385 | } |
| 386 | } |
| 387 | return bytecodes, total_size, nil |
| 388 | } |
| 389 | |
| 390 | // break the instruction into 4 segments of 16 bits |
| 391 | // | flags | offOp1 | offOp0 | offDst | |
no test coverage detected