Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 231d72d

Browse files
authored
Merge pull request #139 from bearsh/sizeof-long-from-cc
adjust type_mapping if processor's data model uses 64bit long integers
2 parents eaf8c81 + 5400ce7 commit 231d72d

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ require (
88
github.com/xlab/pkgconfig v0.0.0-20170226114623-cea12a0fd245
99
golang.org/x/tools v0.1.12
1010
gopkg.in/yaml.v2 v2.4.0
11-
modernc.org/cc/v4 v4.0.0-20220822131148-c47a4b1f7491
12-
modernc.org/token v1.0.0
11+
modernc.org/cc/v4 v4.1.0
12+
modernc.org/token v1.0.1
1313
)
1414

1515
require (
@@ -21,5 +21,5 @@ require (
2121
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
2222
modernc.org/mathutil v1.5.0 // indirect
2323
modernc.org/opt v0.1.3 // indirect
24-
modernc.org/strutil v1.1.2 // indirect
24+
modernc.org/strutil v1.1.3 // indirect
2525
)

go.sum

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,15 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
4848
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
4949
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
5050
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
51-
modernc.org/cc/v4 v4.0.0-20220822131148-c47a4b1f7491 h1:JAyEPvNflhGJq9KF+p9OBkEQT3Ajp74VimOcYmbTHkw=
52-
modernc.org/cc/v4 v4.0.0-20220822131148-c47a4b1f7491/go.mod h1:woK7kLDJB0KdcyuHwwhosSTE2XnbxZraVQNm8PvK28w=
53-
modernc.org/ccorpus2 v0.0.15 h1:pFmjMvxYmv8yA0AZVH8/3VfDD9kn4SLGJcHcv6chKaE=
54-
modernc.org/ccorpus2 v0.0.15/go.mod h1:Wifvo4Q/qS/h1aRoC2TffcHsnxwTikmi1AuLANuucJQ=
55-
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
56-
modernc.org/mathutil v1.4.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
51+
modernc.org/cc/v4 v4.1.0 h1:PlApAKux1sNvreOGs1Hr04FFz35QmAWoa98YFjcdH94=
52+
modernc.org/cc/v4 v4.1.0/go.mod h1:T6KFXc8WI0m9k6IOHuRe9+vB+Pb/AaV8BMZoVqHLm1I=
53+
modernc.org/ccorpus2 v1.1.0 h1:r/Z2+wOD5Tmcs1AMVXJgslE9HgRRROVWo0qUox1kJIo=
54+
modernc.org/ccorpus2 v1.1.0/go.mod h1:Wifvo4Q/qS/h1aRoC2TffcHsnxwTikmi1AuLANuucJQ=
5755
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
5856
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
5957
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
6058
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
61-
modernc.org/strutil v1.1.1/go.mod h1:DE+MQQ/hjKBZS2zNInV5hhcipt5rLPWkmpbGeW5mmdw=
62-
modernc.org/strutil v1.1.2 h1:iFBDH6j1Z0bN/Q9udJnnFoFpENA4252qe/7/5woE5MI=
63-
modernc.org/strutil v1.1.2/go.mod h1:OYajnUAcI/MX+XD/Wx7v1bbdvcQSvxgtb0gC+u3d3eg=
64-
modernc.org/token v1.0.0 h1:a0jaWiNMDhDUtqOj09wvjWWAqd3q7WpBulmL9H2egsk=
65-
modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
59+
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
60+
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
61+
modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
62+
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=

process.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/xlab/pkgconfig/pkg"
1818
"golang.org/x/tools/imports"
1919
"gopkg.in/yaml.v2"
20+
"modernc.org/cc/v4"
2021
)
2122

2223
type Buf int
@@ -86,6 +87,7 @@ func NewProcess(configPath, outputPath string) (*Process, error) {
8687
cfg.Translator = &translator.Config{}
8788
}
8889
cfg.Translator.IgnoredFiles = cfg.Parser.IgnoredPaths
90+
cfg.Translator.LongIs64Bit = unit.ABI.Types[cc.Long].Size == 8
8991
// learn the model
9092
tl, err := translator.New(cfg.Translator)
9193
if err != nil {

translator/translator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type Config struct {
8888
ConstUCharIsString *bool `yaml:"ConstUCharIsString"`
8989

9090
IgnoredFiles []string `yaml:"-"`
91+
LongIs64Bit bool `yaml:"-"`
9192
}
9293

9394
func New(cfg *Config) (*Translator, error) {
@@ -113,8 +114,8 @@ func New(cfg *Config) (*Translator, error) {
113114
rules: cfg.Rules,
114115
constRules: cfg.ConstRules,
115116
typemap: cfg.Typemap,
116-
builtinTypemap: getCTypeMap(constCharAsString, constUCharAsString),
117-
builtinTypemap2: getCTypeMap(true, false),
117+
builtinTypemap: getCTypeMap(constCharAsString, constUCharAsString, cfg.LongIs64Bit),
118+
builtinTypemap2: getCTypeMap(true, false, cfg.LongIs64Bit),
118119
compiledRxs: make(map[RuleAction]RxMap),
119120
compiledPtrTipRxs: make(PtrTipRxMap),
120121
compiledTypeTipRxs: make(TypeTipRxMap),

translator/type_mapping.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var (
3030
InterfaceSliceSpec = GoTypeSpec{Base: "[]interface{}"}
3131
)
3232

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

49+
if longIs64Bit {
50+
config[CTypeSpec{Base: "long", Unsigned: true}] = Uint64Spec
51+
config[CTypeSpec{Base: "long", Signed: true}] = Int64Spec
52+
config[CTypeSpec{Base: "int", Long: true, Unsigned: true}] = Uint64Spec
53+
config[CTypeSpec{Base: "int", Long: true}] = Int64Spec
54+
}
55+
4956
return config
5057
}
5158

0 commit comments

Comments
 (0)