ogma-core-1.7.0: Ogma: Helper tool to interoperate between Copilot and other languages.
Safe HaskellNone
LanguageHaskell2010

Language.Trans.CStructs2Copilot

Description

Generate Copilot struct definitions and instances from structs defined in a C header file.

Working with Copilot structs requires three definitions: the datatype, a Struct instance, and a Typed instance.

This module converts the C structs into CStructs, and then converts those CStructs into Copilot (i.e., Haskell) data type declarations and instance declarations represented as strings.

Synopsis

Documentation

cstructs2CopilotDecls :: TranslationUnit -> Either String [String] Source #

Convert all the CStructs in a header file into the declarations needed in Copilot to use it.

cstruct2CopilotDecls :: CStruct -> [String] Source #

Convert a CStruct into the declarations needed in Copilot to use it.

Individual conversions

cStructToCopilotStruct :: CStruct -> String Source #

Convert a CStruct definition into a Copilot Struct declaration.

For example, given the struct generated by the following definition:

  struct {
    uint8_t f1;
  } a_struct_t;

the corresponding Haskell definition would be:

data AStruct = AStruct
    { aSF1 :: Word8 }
  deriving Generic

structInstance :: CStruct -> String Source #

Convert a CStruct definition into a Copilot Struct instance declaration. For example, for the struct:

  struct {
    uint8_t f1;
  } a_struct_t;

the corresponding Struct instance would be:

  instance Struct AStruct where
    typeName = typeNameDefault
    toValues = toValuesDefault

typedInstance :: CStruct -> String Source #

Convert a CStruct definition to Copilot Typed instance declaration. For example, for the struct:

  struct {
    uint8_t f1;
  } a_struct_t;

the corresponding Typed instance could be:

  instance Typed AStruct where
    typeOf = typeOfDefault

Auxiliary functions

fieldName :: CStruct -> String -> String Source #

Provide a suitable field name for a record field of a CStruct in Haskell.

For example, given the struct:

  struct {
    uint8_t f1;
  } a_struct_t;

the field name in the Haskell record would be aSF1, where the aS and comes from a_struct_t and the final F1 comes from f1.

cStructName2Haskell :: String -> String Source #

Convert a C struct name (e.g., some_type_t) to a Haskell type name (e.g., SomeType).

cTypeName2HaskellType :: String -> String Source #

Return the corresponding type in Copilot/Haskell for a given type.