36 lines
749 B
Go
36 lines
749 B
Go
package asm
|
|
|
|
import "fmt"
|
|
|
|
import "gopkg.in/yaml.v2"
|
|
|
|
type program struct {
|
|
GlobalMemorySize uint64 `yaml:"global_memory_size"`
|
|
FunctionMemorySize uint64 `yaml:"function_memory_size"`
|
|
InstructionLimit uint64 `yaml:"instruction_limit"`
|
|
Functions []function `yaml:"functions"`
|
|
}
|
|
|
|
type function []instruction
|
|
|
|
type instruction []string
|
|
|
|
func parse(src []byte) (*program, error) {
|
|
prog := &program{}
|
|
|
|
err := yaml.UnmarshalStrict(src, &prog)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if prog.GlobalMemorySize == 0 {
|
|
return nil, fmt.Errorf("global_memory_size must be set and non-zero")
|
|
}
|
|
|
|
if prog.FunctionMemorySize == 0 {
|
|
return nil, fmt.Errorf("function_memory_size must be set and non-zero")
|
|
}
|
|
|
|
return prog, nil
|
|
}
|