File: layout.h

package info (click to toggle)
libconvert-binary-c-perl 0.74-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 9,100 kB
  • ctags: 21,416
  • sloc: ansic: 63,666; perl: 18,582; yacc: 2,143; makefile: 44
file content (128 lines) | stat: -rw-r--r-- 3,987 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*******************************************************************************
*
* HEADER: layout.h
*
********************************************************************************
*
* DESCRIPTION: Type layouting routines
*
********************************************************************************
*
* $Project: /Convert-Binary-C $
* $Author: mhx $
* $Date: 2009/03/15 04:10:47 +0100 $
* $Revision: 10 $
* $Source: /ctlib/layout.h $
*
********************************************************************************
*
* Copyright (c) 2002-2009 Marcus Holland-Moritz. All rights reserved.
* This program is free software; you can redistribute it and/or modify
* it under the same terms as Perl itself.
*
*******************************************************************************/

#ifndef _CTLIB_LAYOUT_H
#define _CTLIB_LAYOUT_H

/*===== GLOBAL INCLUDES ======================================================*/


/*===== LOCAL INCLUDES =======================================================*/

#include "ctlib/arch.h"
#include "ctlib/cttype.h"
#include "ctlib/bitfields.h"
#include "ctlib/byteorder.h"


/*===== DEFINES ==============================================================*/

#if ARCH_HAVE_LONG_LONG
#define CTLIB_long_long_SIZE sizeof(long long)
#else
#define CTLIB_long_long_SIZE 8
#endif

#if ARCH_HAVE_LONG_DOUBLE
#define CTLIB_long_double_SIZE sizeof(long double)
#else
#define CTLIB_long_double_SIZE 12
#endif

#define CTLIB_double_SIZE  sizeof(double)
#define CTLIB_float_SIZE   sizeof(float)
#define CTLIB_char_SIZE    sizeof(char)
#define CTLIB_short_SIZE   sizeof(short)
#define CTLIB_long_SIZE    sizeof(long)
#define CTLIB_int_SIZE     sizeof(int)

#define CTLIB_POINTER_SIZE sizeof(void *)

#define CTLIB_ALIGNMENT    (native_alignment ? native_alignment                \
                                           : get_native_alignment())

#define CTLIB_COMPOUND_ALIGNMENT    (native_compound_alignment                 \
                                     ? native_compound_alignment               \
                                     : get_native_compound_alignment())


/*===== TYPEDEFS =============================================================*/

typedef enum {
  GTI_NO_ERROR = 0,
  GTI_NO_STRUCT_DECL
} ErrorGTI;

typedef struct {
  unsigned         alignment;
  unsigned         compound_alignment;
  unsigned         char_size;
  unsigned         int_size;
  unsigned         short_size;
  unsigned         long_size;
  unsigned         long_long_size;
  int              enum_size;
  unsigned         ptr_size;
  unsigned         float_size;
  unsigned         double_size;
  unsigned         long_double_size;
  CByteOrder       byte_order;
  BitfieldLayouter bflayouter;
} LayoutParam;


/*===== EXTERNAL VARIABLES ===================================================*/

#define native_alignment CTlib_native_alignment
extern unsigned native_alignment;

#define native_compound_alignment CTlib_native_compound_alignment
extern unsigned native_compound_alignment;


/*===== FUNCTION PROTOTYPES ==================================================*/

#define get_type_info_generic CTlib_get_type_info_generic
ErrorGTI get_type_info_generic(const LayoutParam *pLP, const TypeSpec *pTS,
                               const Declarator *pDecl, const char *format, ...);

#define layout_compound_generic CTlib_layout_compound_generic
void layout_compound_generic(const LayoutParam *pLP, Struct *pStruct);

#define get_native_alignment CTlib_get_native_alignment
unsigned get_native_alignment(void);

#define get_native_compound_alignment CTlib_get_native_compound_alignment
unsigned get_native_compound_alignment(void);

#define get_native_enum_size CTlib_get_native_enum_size
int get_native_enum_size(void);

#define get_native_unsigned_chars CTlib_get_native_unsigned_chars
int get_native_unsigned_chars(void);

#define get_native_unsigned_bitfields CTlib_get_native_unsigned_bitfields
int get_native_unsigned_bitfields(void);

#endif