Skip to content

Commit

Permalink
adjust type_mapping if processor's data model uses 64bit long integers
Browse files Browse the repository at this point in the history
fortunately modernc.org/cc already has this information. An uptate to
v4.1.0 is needed as otherwise ABI.Types is not public.

Issue: #138

Signed-off-by: Martin Gysel <me@bearsh.org>
  • Loading branch information
bearsh committed Nov 17, 2022
1 parent eaf8c81 commit ecc730f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/xlab/pkgconfig v0.0.0-20170226114623-cea12a0fd245
golang.org/x/tools v0.1.12
gopkg.in/yaml.v2 v2.4.0
modernc.org/cc/v4 v4.0.0-20220822131148-c47a4b1f7491
modernc.org/token v1.0.0
modernc.org/cc/v4 v4.1.0
modernc.org/token v1.0.1
)

require (
Expand All @@ -21,5 +21,5 @@ require (
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/strutil v1.1.2 // indirect
modernc.org/strutil v1.1.3 // indirect
)
19 changes: 8 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,15 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
modernc.org/cc/v4 v4.0.0-20220822131148-c47a4b1f7491 h1:JAyEPvNflhGJq9KF+p9OBkEQT3Ajp74VimOcYmbTHkw=
modernc.org/cc/v4 v4.0.0-20220822131148-c47a4b1f7491/go.mod h1:woK7kLDJB0KdcyuHwwhosSTE2XnbxZraVQNm8PvK28w=
modernc.org/ccorpus2 v0.0.15 h1:pFmjMvxYmv8yA0AZVH8/3VfDD9kn4SLGJcHcv6chKaE=
modernc.org/ccorpus2 v0.0.15/go.mod h1:Wifvo4Q/qS/h1aRoC2TffcHsnxwTikmi1AuLANuucJQ=
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/mathutil v1.4.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/cc/v4 v4.1.0 h1:PlApAKux1sNvreOGs1Hr04FFz35QmAWoa98YFjcdH94=
modernc.org/cc/v4 v4.1.0/go.mod h1:T6KFXc8WI0m9k6IOHuRe9+vB+Pb/AaV8BMZoVqHLm1I=
modernc.org/ccorpus2 v1.1.0 h1:r/Z2+wOD5Tmcs1AMVXJgslE9HgRRROVWo0qUox1kJIo=
modernc.org/ccorpus2 v1.1.0/go.mod h1:Wifvo4Q/qS/h1aRoC2TffcHsnxwTikmi1AuLANuucJQ=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/strutil v1.1.1/go.mod h1:DE+MQQ/hjKBZS2zNInV5hhcipt5rLPWkmpbGeW5mmdw=
modernc.org/strutil v1.1.2 h1:iFBDH6j1Z0bN/Q9udJnnFoFpENA4252qe/7/5woE5MI=
modernc.org/strutil v1.1.2/go.mod h1:OYajnUAcI/MX+XD/Wx7v1bbdvcQSvxgtb0gC+u3d3eg=
modernc.org/token v1.0.0 h1:a0jaWiNMDhDUtqOj09wvjWWAqd3q7WpBulmL9H2egsk=
modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
2 changes: 2 additions & 0 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/xlab/pkgconfig/pkg"
"golang.org/x/tools/imports"
"gopkg.in/yaml.v2"
"modernc.org/cc/v4"
)

type Buf int
Expand Down Expand Up @@ -86,6 +87,7 @@ func NewProcess(configPath, outputPath string) (*Process, error) {
cfg.Translator = &translator.Config{}
}
cfg.Translator.IgnoredFiles = cfg.Parser.IgnoredPaths
cfg.Translator.LongIs64Bit = unit.ABI.Types[cc.Long].Size == 8
// learn the model
tl, err := translator.New(cfg.Translator)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Config struct {
ConstUCharIsString *bool `yaml:"ConstUCharIsString"`

IgnoredFiles []string `yaml:"-"`
LongIs64Bit bool `yaml:"-"`
}

func New(cfg *Config) (*Translator, error) {
Expand All @@ -113,8 +114,8 @@ func New(cfg *Config) (*Translator, error) {
rules: cfg.Rules,
constRules: cfg.ConstRules,
typemap: cfg.Typemap,
builtinTypemap: getCTypeMap(constCharAsString, constUCharAsString),
builtinTypemap2: getCTypeMap(true, false),
builtinTypemap: getCTypeMap(constCharAsString, constUCharAsString, cfg.LongIs64Bit),
builtinTypemap2: getCTypeMap(true, false, cfg.LongIs64Bit),
compiledRxs: make(map[RuleAction]RxMap),
compiledPtrTipRxs: make(PtrTipRxMap),
compiledTypeTipRxs: make(TypeTipRxMap),
Expand Down
9 changes: 8 additions & 1 deletion translator/type_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
InterfaceSliceSpec = GoTypeSpec{Base: "[]interface{}"}
)

func getCTypeMap(constCharIsString, constUCharIsString bool) CTypeMap {
func getCTypeMap(constCharIsString, constUCharIsString, longIs64Bit bool) CTypeMap {
config := make(CTypeMap, len(builtinCTypeMap)+2)
for k, v := range builtinCTypeMap {
config[k] = v
Expand All @@ -46,6 +46,13 @@ func getCTypeMap(constCharIsString, constUCharIsString bool) CTypeMap {
config[CTypeSpec{Base: "char", Const: true, Unsigned: true, Pointers: 1}] = UStringSpec
}

if longIs64Bit {
config[CTypeSpec{Base: "long", Unsigned: true}] = Uint64Spec
config[CTypeSpec{Base: "long", Signed: true}] = Int64Spec
config[CTypeSpec{Base: "int", Long: true}] = Int64Spec
config[CTypeSpec{Base: "int", Long: true, Unsigned: true}] = Uint64Spec
}

return config
}

Expand Down

0 comments on commit ecc730f

Please sign in to comment.