Given a CASM program it returns its encoded bytecode and a total size of processed instructions
(code string)
| 20 | |
| 21 | // Given a CASM program it returns its encoded bytecode and a total size of processed instructions |
| 22 | func CasmToBytecode(code string) ([]*f.Element, uint8, error) { |
| 23 | casmAst, err := parser.ParseString("", code) |
| 24 | if err != nil { |
| 25 | return nil, 0, err |
| 26 | } |
| 27 | // Ast To Instruction List |
| 28 | wordList, err := astToInstruction(casmAst) |
| 29 | if err != nil { |
| 30 | return nil, 0, err |
| 31 | } |
| 32 | // Instruction to bytecode |
| 33 | return encodeInstructionListToBytecode(wordList) |
| 34 | } |
| 35 | |
| 36 | // Given a CASM ast it returns a list of instructions |
| 37 | func astToInstruction(ast *CasmProgram) ([]Word, error) { |