Skip to content

Commit

Permalink
Add size and alignment for complex types to CIL machine configuration
Browse files Browse the repository at this point in the history
Requires running ./configure after pulling if it is not a fresh checkout

Should mean complex and tgmath work now, more tests needed though. References #8, References #9
  • Loading branch information
michael-schwarz committed Jan 15, 2020
1 parent f6cce92 commit 65bf016
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 40 deletions.
6 changes: 6 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ $(OBJDIR)/machdep.ml : src/machdep-ml.c configure.ac Makefile.in
@echo " sizeof_float: int; (* Size of \"float\" *)" >> $@
@echo " sizeof_double: int; (* Size of \"double\" *)" >> $@
@echo " sizeof_longdouble: int; (* Size of \"long double\" *)" >> $@
@echo " sizeof_floatcomplex: int; (* Size of \"float _Complex\" *)" >> $@
@echo " sizeof_doublecomplex: int; (* Size of \"double _Complex\" *)" >> $@
@echo " sizeof_longdoublecomplex: int; (* Size of \"long double _Complex\" *)" >> $@
@echo " sizeof_void: int; (* Size of \"void\" *)" >> $@
@echo " sizeof_fun: int; (* Size of function *)" >> $@
@echo " size_t: string; (* Type of \"sizeof(T)\" *)" >> $@
Expand All @@ -181,6 +184,9 @@ $(OBJDIR)/machdep.ml : src/machdep-ml.c configure.ac Makefile.in
@echo " alignof_float: int; (* Alignment of \"float\" *)" >> $@
@echo " alignof_double: int; (* Alignment of \"double\" *)" >> $@
@echo " alignof_longdouble: int; (* Alignment of \"long double\" *)" >> $@
@echo " alignof_floatcomplex: int; (* Alignment of \"float _Complex\" *)" >> $@
@echo " alignof_doublecomplex: int; (* Alignment of \"double _Complex\" *)" >> $@
@echo " alignof_longdoublecomplex: int; (* Alignment of \"long double _Complex\" *)" >> $@
@echo " alignof_str: int; (* Alignment of strings *)" >> $@
@echo " alignof_fun: int; (* Alignment of function *)" >> $@
@echo " alignof_aligned: int; (* Alignment of anything with the \"aligned\" attribute *)" >> $@
Expand Down
11 changes: 7 additions & 4 deletions src/cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2184,9 +2184,9 @@ let rec alignOf_int t =
| TFloat(FFloat, _) -> !M.theMachine.M.alignof_float
| TFloat(FDouble, _) -> !M.theMachine.M.alignof_double
| TFloat(FLongDouble, _) -> !M.theMachine.M.alignof_longdouble
| TFloat(FComplexFloat, _) -> !M.theMachine.M.alignof_float (* TODO! *)
| TFloat(FComplexDouble, _) -> !M.theMachine.M.alignof_double (* TODO! *)
| TFloat(FComplexLongDouble, _) -> !M.theMachine.M.alignof_longdouble (* TODO! *)
| TFloat(FComplexFloat, _) -> !M.theMachine.M.alignof_floatcomplex
| TFloat(FComplexDouble, _) -> !M.theMachine.M.alignof_doublecomplex
| TFloat(FComplexLongDouble, _) -> !M.theMachine.M.alignof_longdoublecomplex
| TNamed (t, _) -> alignOf_int t.ttype
| TArray (t, _, _) -> alignOf_int t
| TPtr _ | TBuiltin_va_list _ -> !M.theMachine.M.alignof_ptr
Expand Down Expand Up @@ -2446,7 +2446,10 @@ and bitsSizeOf t =
| TInt (ik,_) -> 8 * (bytesSizeOfInt ik)
| TFloat(FDouble, _) -> 8 * !M.theMachine.M.sizeof_double
| TFloat(FLongDouble, _) -> 8 * !M.theMachine.M.sizeof_longdouble
| TFloat _ -> 8 * !M.theMachine.M.sizeof_float
| TFloat(FFloat, _) -> 8 * !M.theMachine.M.sizeof_float
| TFloat(FComplexDouble, _) -> 8 * !M.theMachine.M.sizeof_doublecomplex
| TFloat(FComplexLongDouble, _) -> 8 * !M.theMachine.M.sizeof_longdoublecomplex
| TFloat(FComplexFloat, _) -> 8 * !M.theMachine.M.sizeof_floatcomplex
| TEnum (ei, _) -> bitsSizeOf (TInt(ei.ekind, []))
| TPtr _ -> 8 * !M.theMachine.M.sizeof_ptr
| TBuiltin_va_list _ -> 8 * !M.theMachine.M.sizeof_ptr
Expand Down
108 changes: 72 additions & 36 deletions src/machdep-ml.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ int main(int argc, char **argv)
{
int env = argc == 2 && !strcmp(argv[1], "--env");
int alignof_short, alignof_int, alignof_long, alignof_ptr, alignof_enum,
alignof_float, alignof_double, alignof_longdouble, sizeof_fun,
alignof_fun, alignof_str, alignof_aligned, alignof_longlong,
alignof_float, alignof_double, alignof_longdouble,
alignof_floatcomplex, alignof_doublecomplex, alignof_longdoublecomplex,
sizeof_fun,
alignof_fun, alignof_str, alignof_aligned, alignof_longlong,
little_endian, char_is_unsigned, alignof_bool;

// The alignment of a short
Expand Down Expand Up @@ -195,6 +197,33 @@ int main(int argc, char **argv)
alignof_longdouble = (intptr_t)(&((struct s1*)0)->ld);
}

// The alignment of a float complex
{
struct floatstruct {
char c;
float _Complex f;
};
alignof_floatcomplex = (intptr_t)(&((struct floatstruct*)0)->f);
}

// The alignment of double complex
{
struct s1 {
char c;
double _Complex d;
};
alignof_doublecomplex = (intptr_t)(&((struct s1*)0)->d);
}

// The alignment of long double complex
{
struct s1 {
char c;
long double _Complex ld;
};
alignof_longdoublecomplex = (intptr_t)(&((struct s1*)0)->ld);
}

alignof_str = __alignof("a string");
alignof_fun = __alignof(main);

Expand Down Expand Up @@ -231,7 +260,7 @@ int main(int argc, char **argv)
{
fprintf(stderr, "Generating CIL_MACHINE machine dependency information string (for CIL)\n");
printf("short=%d,%d int=%d,%d long=%d,%d long_long=%d,%d pointer=%d,%d "
"alignof_enum=%d float=%d,%d double=%d,%d long_double=%d,%d void=%d "
"alignof_enum=%d float=%d,%d double=%d,%d long_double=%d,%d float_complex=%d,%d double_complex=%d,%d long_double_complex=%d,%d void=%d "
"bool=%d,%d fun=%d,%d alignof_string=%d max_alignment=%d size_t=%s "
"wchar_t=%s char_signed=%s const_string_literals=%s "
"big_endian=%s __thread_is_keyword=%s __builtin_va_list=%s "
Expand All @@ -240,7 +269,8 @@ int main(int argc, char **argv)
(int)sizeof(long), alignof_long, (int)sizeof(long long), alignof_longlong,
(int)sizeof(int *), alignof_ptr, alignof_enum,
(int)sizeof(float), alignof_float, (int)sizeof(double), alignof_double,
(int)sizeof(long double), alignof_longdouble, (int)sizeof(void),
(int)sizeof(long double), alignof_longdouble, (int)sizeof(float _Complex), alignof_floatcomplex, (int)sizeof(double _Complex), alignof_doublecomplex,
(int)sizeof(long double _Complex), alignof_longdoublecomplex, (int)sizeof(void),
(int)sizeof(bool), alignof_bool,
sizeof_fun, alignof_fun, alignof_str, alignof_aligned,
underscore(TYPE_SIZE_T), underscore(TYPE_WCHAR_T),
Expand All @@ -258,38 +288,44 @@ int main(int argc, char **argv)
printf("\t version = \"%s\";\n", VERSION);

// Size of certain types
printf("\t sizeof_short = %d;\n", (int)sizeof(short));
printf("\t sizeof_int = %d;\n", (int)sizeof(int));
printf("\t sizeof_bool = %d;\n", (int)sizeof(bool));
printf("\t sizeof_long = %d;\n", (int)sizeof(long));
printf("\t sizeof_longlong = %d;\n", (int)sizeof(LONGLONG));
printf("\t sizeof_ptr = %d;\n", (int)sizeof(int *));
printf("\t sizeof_float = %d;\n", (int)sizeof(float));
printf("\t sizeof_double = %d;\n", (int)sizeof(double));
printf("\t sizeof_longdouble = %d;\n", (int)sizeof(long double));
printf("\t sizeof_void = %d;\n", (int)sizeof(void));
printf("\t sizeof_fun = %d;\n", (int)sizeof_fun);
printf("\t size_t = \"%s\";\n", TYPE_SIZE_T);
printf("\t wchar_t = \"%s\";\n", TYPE_WCHAR_T);
printf("\t alignof_short = %d;\n", alignof_short);
printf("\t alignof_int = %d;\n", alignof_int);
printf("\t alignof_bool = %d;\n", alignof_bool);
printf("\t alignof_long = %d;\n", alignof_long);
printf("\t alignof_longlong = %d;\n", alignof_longlong);
printf("\t alignof_ptr = %d;\n", alignof_ptr);
printf("\t alignof_enum = %d;\n", alignof_enum);
printf("\t alignof_float = %d;\n", alignof_float);
printf("\t alignof_double = %d;\n", alignof_double);
printf("\t alignof_longdouble = %d;\n", alignof_longdouble);
printf("\t alignof_str = %d;\n", alignof_str);
printf("\t alignof_fun = %d;\n", alignof_fun);
printf("\t alignof_aligned = %d;\n", alignof_aligned);
printf("\t char_is_unsigned = %s;\n", char_is_unsigned ? "true" : "false");
printf("\t const_string_literals = %s;\n", CONST_STRING_LITERALS);
printf("\t underscore_name = %s;\n", UNDERSCORE_NAME);
printf("\t __builtin_va_list = %s;\n", HAVE_BUILTIN_VA_LIST);
printf("\t __thread_is_keyword = %s;\n", THREAD_IS_KEYWORD);
printf("\t little_endian = %s;\n", little_endian ? "true" : "false");
printf("\t sizeof_short = %d;\n", (int)sizeof(short));
printf("\t sizeof_int = %d;\n", (int)sizeof(int));
printf("\t sizeof_bool = %d;\n", (int)sizeof(bool));
printf("\t sizeof_long = %d;\n", (int)sizeof(long));
printf("\t sizeof_longlong = %d;\n", (int)sizeof(LONGLONG));
printf("\t sizeof_ptr = %d;\n", (int)sizeof(int *));
printf("\t sizeof_float = %d;\n", (int)sizeof(float));
printf("\t sizeof_double = %d;\n", (int)sizeof(double));
printf("\t sizeof_longdouble = %d;\n", (int)sizeof(long double));
printf("\t sizeof_floatcomplex = %d;\n", (int)sizeof(float _Complex));
printf("\t sizeof_doublecomplex = %d;\n", (int)sizeof(double _Complex));
printf("\t sizeof_longdoublecomplex = %d;\n", (int)sizeof(long double _Complex));
printf("\t sizeof_void = %d;\n", (int)sizeof(void));
printf("\t sizeof_fun = %d;\n", (int)sizeof_fun);
printf("\t size_t = \"%s\";\n", TYPE_SIZE_T);
printf("\t wchar_t = \"%s\";\n", TYPE_WCHAR_T);
printf("\t alignof_short = %d;\n", alignof_short);
printf("\t alignof_int = %d;\n", alignof_int);
printf("\t alignof_bool = %d;\n", alignof_bool);
printf("\t alignof_long = %d;\n", alignof_long);
printf("\t alignof_longlong = %d;\n", alignof_longlong);
printf("\t alignof_ptr = %d;\n", alignof_ptr);
printf("\t alignof_enum = %d;\n", alignof_enum);
printf("\t alignof_float = %d;\n", alignof_float);
printf("\t alignof_double = %d;\n", alignof_double);
printf("\t alignof_longdouble = %d;\n", alignof_longdouble);
printf("\t alignof_floatcomplex = %d;\n", alignof_floatcomplex);
printf("\t alignof_doublecomplex = %d;\n", alignof_doublecomplex);
printf("\t alignof_longdoublecomplex = %d;\n", alignof_longdoublecomplex);
printf("\t alignof_str = %d;\n", alignof_str);
printf("\t alignof_fun = %d;\n", alignof_fun);
printf("\t alignof_aligned = %d;\n", alignof_aligned);
printf("\t char_is_unsigned = %s;\n", char_is_unsigned ? "true" : "false");
printf("\t const_string_literals = %s;\n", CONST_STRING_LITERALS);
printf("\t underscore_name = %s;\n", UNDERSCORE_NAME);
printf("\t __builtin_va_list = %s;\n", HAVE_BUILTIN_VA_LIST);
printf("\t __thread_is_keyword = %s;\n", THREAD_IS_KEYWORD);
printf("\t little_endian = %s;\n", little_endian ? "true" : "false");
}
return 0;
}
6 changes: 6 additions & 0 deletions src/machdepenv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ let modelParse (s:string) : mach =
alignof_enum = getInt entries "alignof_enum";
sizeof_float = getSizeof entries "float";
alignof_float = getAlignof entries "float";
sizeof_floatcomplex = getSizeof entries "float_complex";
alignof_floatcomplex = getAlignof entries "float_complex";
sizeof_double = getSizeof entries "double";
alignof_double = getAlignof entries "double";
sizeof_doublecomplex = getSizeof entries "double_complex";
alignof_doublecomplex = getAlignof entries "double_complex";
sizeof_longdouble = getSizeof entries "long_double";
alignof_longdouble = getAlignof entries "long_double";
sizeof_longdoublecomplex = getSizeof entries "long_double_complex";
alignof_longdoublecomplex = getAlignof entries "long_double_complex";
sizeof_void = getSizeof entries "void";
sizeof_fun = getSizeof entries "fun";
alignof_fun = getAlignof entries "fun";
Expand Down

0 comments on commit 65bf016

Please sign in to comment.