Skip to content

Commit

Permalink
simple: support signals
Browse files Browse the repository at this point in the history
  • Loading branch information
fsasm committed May 22, 2024
1 parent 4a7b61e commit 60b11cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 38 deletions.
48 changes: 12 additions & 36 deletions simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,22 @@ import (
"text/template"
)

type ValueType string

const (
StdLogic ValueType = "std"
StdLogicVector ValueType = "slv"
Integer ValueType = "int"
String ValueType = "str"
RawType ValueType = "raw"
)

type GenericTmpl struct {
type Generic struct {
Name string
Value string
Type ValueType
}

type SignalImpl struct {
Name string
Type ValueType
VecSize int
InitValue string
}
type simpleTbTmpl struct {
Name string
UUTEntity string
// TODO signals, generics,
Generics []Generic
}

type Generic struct {
Name string
Value string
type Signal struct {
Name string
Type string
}

type SimpleTbConfig struct {
Filename string `json:"filename"`
Name string `json:"name"`
UUTEntiy string `json:"uut"`
UUTEntity string `json:"uut"`
Generics []Generic `json:"generics"`
Signals []Signal `json:"signals"`
}

func expandType(t string) string {
Expand Down Expand Up @@ -98,6 +75,11 @@ func GenerateSimpleTB(config SimpleTbConfig, outputDir string) {
}
defer targetFile.Close()

// preprocess the config
for i, s := range config.Signals {
config.Signals[i].Type = expandType(s.Type)
}

// start the template engine
helpers := map[string]interface{}{
"notLast": func(i, length int) bool {
Expand All @@ -109,11 +91,5 @@ func GenerateSimpleTB(config SimpleTbConfig, outputDir string) {
panic(err)
}

data := simpleTbTmpl{
Name: config.Name,
UUTEntity: config.UUTEntiy,
Generics: config.Generics,
}

err = t.Execute(targetFile, data)
err = t.Execute(targetFile, config)
}
9 changes: 7 additions & 2 deletions templates/simple.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ architecture tb of {{.Name}} is
signal clk : std_logic := '0';
signal rst_n : std_logic := '0';
signal tb_done : boolean := false;

{{range .Signals -}}
signal uut_{{.Name}} : {{.Type}};
{{end -}}
-- USER SIGNALS
begin
uut : entity work.{{.UUTEntity}}
Expand All @@ -23,8 +27,9 @@ begin
{{- end}}
){{- end}}
port map (
-- TODO other signals

{{range .Signals -}}
{{.Name}} => uut_{{.Name}},
{{end}}
clk => clk,
rst_n => rst_n
);
Expand Down

0 comments on commit 60b11cf

Please sign in to comment.