2021-11-18 19:35:24 -10:00
|
|
|
package asm
|
2021-11-16 21:08:46 -10:00
|
|
|
|
2021-11-20 18:27:06 -10:00
|
|
|
import "fmt"
|
|
|
|
|
|
2021-11-16 21:08:46 -10:00
|
|
|
import "gopkg.in/yaml.v2"
|
|
|
|
|
|
2021-11-18 17:43:13 -10:00
|
|
|
type program struct {
|
2021-11-20 18:27:06 -10:00
|
|
|
GlobalMemorySize uint64 `yaml:"global_memory_size"`
|
|
|
|
|
FunctionMemorySize uint64 `yaml:"function_memory_size"`
|
|
|
|
|
Functions []function `yaml:"functions"`
|
2021-11-16 21:08:46 -10:00
|
|
|
}
|
|
|
|
|
|
2021-11-18 17:43:13 -10:00
|
|
|
type function []instruction
|
2021-11-16 21:08:46 -10:00
|
|
|
|
2021-11-18 17:43:13 -10:00
|
|
|
type instruction []string
|
2021-11-16 21:08:46 -10:00
|
|
|
|
2021-11-18 17:43:13 -10:00
|
|
|
func parse(src []byte) (*program, error) {
|
|
|
|
|
prog := &program{}
|
|
|
|
|
|
|
|
|
|
err := yaml.UnmarshalStrict(src, &prog)
|
2021-11-16 21:08:46 -10:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-20 18:27:06 -10:00
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-16 21:08:46 -10:00
|
|
|
return prog, nil
|
|
|
|
|
}
|