diff options
| author | Siva Chandra Reddy <sivachandra@google.com> | 2019-11-05 11:40:26 -0800 |
|---|---|---|
| committer | Siva Chandra Reddy <sivachandra@google.com> | 2019-11-22 13:02:24 -0800 |
| commit | b47f9eb55d1814e006d1a2a971ff6272ebd89bcb (patch) | |
| tree | 1339b2e39ff49de41a332a5f640177cd40665bf8 /libc/spec | |
| parent | a6150b48cea00ab31e9335cc73770327acc4cb3a (diff) | |
| download | bcm5719-llvm-b47f9eb55d1814e006d1a2a971ff6272ebd89bcb.tar.gz bcm5719-llvm-b47f9eb55d1814e006d1a2a971ff6272ebd89bcb.zip | |
[libc] Add a TableGen based header generator.
Summary:
* The Python header generator has been removed.
* Docs giving a highlevel overview of the header gen scheme have been
added.
Reviewers: phosek, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D70197
Diffstat (limited to 'libc/spec')
| -rw-r--r-- | libc/spec/spec.td | 74 | ||||
| -rw-r--r-- | libc/spec/stdc.td | 178 |
2 files changed, 252 insertions, 0 deletions
diff --git a/libc/spec/spec.td b/libc/spec/spec.td new file mode 100644 index 00000000000..855dd6aaa77 --- /dev/null +++ b/libc/spec/spec.td @@ -0,0 +1,74 @@ +class Type {} + +class NamedType<string name> : Type { + string Name = name; +} + +class Field<string name, Type type> { + string Name = name; + Type FieldType = type; +} + +// Class to describe concrete structs specified by a standard. +class Struct<string name> : NamedType<name> { + list<Field> Fields; +} + +class PtrType<Type type> : Type { + Type PointeeType = type; +} + +class ConstType<Type type> : Type { + Type UnqualifiedType = type; +} + +class RestrictedPtrType<Type type> : Type { + Type PointeeType = type; +} + +// Builtin types. +def VarArgType : Type {} +def VoidType : NamedType<"void">; +def IntType : NamedType<"int">; +def FloatType : NamedType<"float">; +def DoubleType : NamedType<"double">; +def LongDoubleType : NamedType<"long double">; +def CharType : NamedType<"char">; + +class Macro<string name> { + string Name = name; +} + +class Annotation {} + +class RetValSpec<Type type, list<Annotation> annotations = []> { + Type ReturnType = type; + list<Annotation> Annotations = annotations; +} + +class ArgSpec<Type type, list<Annotation> annotations = [], string name = ""> { + Type ArgType = type; + list<Annotation> Annotations = annotations; + string Name = name; +} + +class FunctionSpec<string name, RetValSpec return, list<ArgSpec> args> { + string Name = name; + RetValSpec Return = return; + list<ArgSpec> Args = args; +} + +class HeaderSpec<string name, + list<Macro> macros, + list<Type> types, + list<FunctionSpec> functions> { + string Name = name; + list<FunctionSpec> Functions = functions; + list<Type> Types = types; + list<Macro> Macros = macros; +} + +class StandardSpec<string name> { + string Name = name; + list<HeaderSpec> Headers; +} diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td new file mode 100644 index 00000000000..154214dc516 --- /dev/null +++ b/libc/spec/stdc.td @@ -0,0 +1,178 @@ +def StdC : StandardSpec<"stdc"> { + PtrType VoidPtr = PtrType<VoidType>; + ConstType ConstVoidPtr = ConstType<VoidPtr>; + RestrictedPtrType VoidRestrictedPtr = RestrictedPtrType<VoidType>; + ConstType ConstVoidRestrictedPtr = ConstType<VoidRestrictedPtr>; + + PtrType CharPtr = PtrType<CharType>; + ConstType ConstCharPtr = ConstType<CharPtr>; + RestrictedPtrType CharRestrictedPtr = RestrictedPtrType<CharType>; + ConstType ConstCharRestrictedPtr = ConstType<CharRestrictedPtr>; + + NamedType SizeTType = NamedType<"size_t">; + + HeaderSpec String = HeaderSpec< + "string.h", + [ + Macro<"NULL">, + ], + [ + SizeTType, + ], + [ + FunctionSpec< + "memcpy", + RetValSpec<VoidPtr>, + [ArgSpec<VoidRestrictedPtr>, + ArgSpec<ConstVoidRestrictedPtr>, + ArgSpec<SizeTType>] + >, + FunctionSpec< + "memmove", + RetValSpec<VoidPtr>, + [ArgSpec<VoidPtr>, ArgSpec<ConstVoidPtr>, ArgSpec<SizeTType>] + >, + FunctionSpec< + "memcmp", + RetValSpec<IntType>, + [ArgSpec<ConstVoidPtr>, ArgSpec<ConstVoidPtr>, ArgSpec<SizeTType>] + >, + FunctionSpec< + "memchr", + RetValSpec<VoidPtr>, + [ArgSpec<ConstVoidPtr>, ArgSpec<IntType>, ArgSpec<SizeTType>] + >, + FunctionSpec< + "memset", + RetValSpec<VoidPtr>, + [ArgSpec<VoidPtr>, ArgSpec<IntType>, ArgSpec<SizeTType>] + >, + FunctionSpec< + "strcpy", + RetValSpec<CharPtr>, + [ArgSpec<CharRestrictedPtr>, ArgSpec<ConstCharRestrictedPtr>] + >, + FunctionSpec< + "strncpy", + RetValSpec<CharPtr>, + [ArgSpec<CharRestrictedPtr>, + ArgSpec<ConstCharRestrictedPtr>, + ArgSpec<SizeTType>] + >, + FunctionSpec< + "strcat", + RetValSpec<CharPtr>, + [ArgSpec<CharRestrictedPtr>, ArgSpec<ConstCharRestrictedPtr>] + >, + FunctionSpec< + "strncat", + RetValSpec<CharPtr>, + [ArgSpec<CharPtr>, ArgSpec<ConstCharPtr>, ArgSpec<SizeTType>] + >, + FunctionSpec< + "strcmp", + RetValSpec<IntType>, + [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>] + >, + FunctionSpec< + "strcoll", + RetValSpec<IntType>, + [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>] + >, + FunctionSpec< + "strncmp", + RetValSpec<IntType>, + [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>, ArgSpec<SizeTType>] + >, + FunctionSpec< + "strxfrm", + RetValSpec<SizeTType>, + [ArgSpec<CharRestrictedPtr>, + ArgSpec<ConstCharRestrictedPtr>, + ArgSpec<SizeTType>] + >, + FunctionSpec< + "strchr", + RetValSpec<CharPtr>, + [ArgSpec<ConstCharPtr>, ArgSpec<IntType>] + >, + FunctionSpec< + "strcspn", + RetValSpec<SizeTType>, + [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>] + >, + FunctionSpec< + "strpbrk", + RetValSpec<CharPtr>, + [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>] + >, + FunctionSpec< + "strrchr", + RetValSpec<CharPtr>, + [ArgSpec<ConstCharPtr>, ArgSpec<IntType>] + >, + FunctionSpec< + "strspn", + RetValSpec<SizeTType>, + [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>] + >, + FunctionSpec< + "strstr", + RetValSpec<CharPtr>, + [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>] + >, + FunctionSpec< + "strtok", + RetValSpec<CharPtr>, + [ArgSpec<CharRestrictedPtr>, ArgSpec<ConstCharRestrictedPtr>] + >, + FunctionSpec< + "strerror", + RetValSpec<CharPtr>, + [ArgSpec<IntType>] + >, + FunctionSpec< + "strlen", + RetValSpec<SizeTType>, + [ArgSpec<ConstCharPtr>] + >, + ] + >; + + HeaderSpec Math = HeaderSpec< + "math.h", + [], // Macros + [ + NamedType<"float_t">, + NamedType<"double_t">, + ], + [ + FunctionSpec<"acos", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>, + FunctionSpec<"acosl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>, + ] + >; + + HeaderSpec StdIO = HeaderSpec< + "stdio.h", + [], // Macros + [ // Types + SizeTType, + ], + [ + FunctionSpec< + "snprintf", + RetValSpec<IntType>, + [ArgSpec<CharPtr>, + ArgSpec<SizeTType>, + ArgSpec<ConstCharRestrictedPtr>, + ArgSpec<VarArgType>] + >, + ] + >; + + let Headers = [ + Math, + String, + StdIO, + ]; +} |

