diff options
author | Ayke van Laethem <[email protected]> | 2019-04-20 15:10:27 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-04-25 10:48:56 +0200 |
commit | 9c46ac4eed1356ee3feb7e2e10fcc6c7c8a80103 (patch) | |
tree | 9dda4ae33e445c4e8efd9e53c21dab06b4817631 /loader | |
parent | b2e96fc35af54b9975f2ce02849bc17f208bf0e3 (diff) | |
download | tinygo-9c46ac4eed1356ee3feb7e2e10fcc6c7c8a80103.tar.gz tinygo-9c46ac4eed1356ee3feb7e2e10fcc6c7c8a80103.zip |
cgo: implement char type
This type is a bit more difficult because it can be signed or unsigned
depending on the target platform.
Diffstat (limited to 'loader')
-rw-r--r-- | loader/cgo.go | 1 | ||||
-rw-r--r-- | loader/libclang.go | 16 |
2 files changed, 16 insertions, 1 deletions
diff --git a/loader/cgo.go b/loader/cgo.go index dc217f962..8cabce7d2 100644 --- a/loader/cgo.go +++ b/loader/cgo.go @@ -66,6 +66,7 @@ var cgoAliases = map[string]string{ // somehow from C. This is done by adding some typedefs to get the size of each // type. const cgoTypes = ` +typedef char _Cgo_char; typedef signed char _Cgo_schar; typedef unsigned char _Cgo_uchar; typedef short _Cgo_short; diff --git a/loader/libclang.go b/loader/libclang.go index 4c79fcaf9..6166e1562 100644 --- a/loader/libclang.go +++ b/loader/libclang.go @@ -203,7 +203,19 @@ func tinygo_clang_globals_visitor(c, parent C.GoCXCursor, client_data C.CXClient expr := expr.(*ast.Ident) typeSize := C.clang_Type_getSizeOf(underlyingType) switch expr.Name { - // TODO: plain char (may be signed or unsigned) + case "C.char": + if typeSize != 1 { + // This happens for some very special purpose architectures + // (DSPs etc.) that are not currently targeted. + // https://www.embecosm.com/2017/04/18/non-8-bit-char-support-in-clang-and-llvm/ + panic("unknown char width") + } + switch underlyingType.kind { + case C.CXType_Char_S: + expr.Name = "int8" + case C.CXType_Char_U: + expr.Name = "uint8" + } case "C.schar", "C.short", "C.int", "C.long", "C.longlong": switch typeSize { case 1: @@ -253,6 +265,8 @@ func getString(clangString C.CXString) (s string) { func (info *fileInfo) makeASTType(typ C.CXType) ast.Expr { var typeName string switch typ.kind { + case C.CXType_Char_S, C.CXType_Char_U: + typeName = "C.char" case C.CXType_SChar: typeName = "C.schar" case C.CXType_UChar: |