Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[GH #844] add missing auto::alignof files

Add files to MANIFEST
Use auto::alignof as last auto step
  • Loading branch information...
commit 665f7d5096b157e68a73fda10b5047c429e01f41 1 parent 1a2f59b
@rurban rurban authored
View
2  MANIFEST
@@ -120,6 +120,8 @@ compilers/tge/TGE/Tree.pir [tge]
compilers/tge/tgc.pir [tge]
config/README.pod []doc
config/auto/arch.pm []
+config/auto/alignof.pm []
+config/auto/alignof/test_c.in []
config/auto/attributes.pm []
config/auto/attributes/test_c.in []
config/auto/backtrace.pm []
View
105 config/auto/alignof.pm
@@ -0,0 +1,105 @@
+# Copyright (C) 2012, Parrot Foundation.
+
+=head1 NAME
+
+config/auto/alignof.pm - clang++ offsetof values
+
+=head1 DESCRIPTION
+
+Determines the offsetof values of our types for clang++.
+
+=cut
+
+package auto::alignof;
+
+use strict;
+use warnings;
+
+use base qw(Parrot::Configure::Step);
+
+use Parrot::Configure::Utils ':auto';
+
+sub _init {
+ my $self = shift;
+ my %data;
+ $data{description} = q{Determine offsetof values for our types};
+ $data{result} = q{};
+ return \%data;
+}
+
+sub runstep {
+ my ( $self, $conf ) = @_;
+
+ # This step only needed for clang++
+ if (!$conf->data->get('clang') or !$conf->data->get('g++')) {
+ $conf->debug("DEBUG: auto::alignof is only needed for clang++\n");
+ $self->set_result('skipped');
+ return 1;
+ }
+
+ my %types = (
+ intval => $conf->data->get('iv'),
+ floatval => $conf->data->get('nv'),
+ stringptr => 'STRING *',
+ pmcptr => 'PMC *',
+ char => 'char',
+ short => 'short',
+ int => 'int',
+ long => 'long',
+ uchar => 'unsigned char',
+ ushort => 'unsigned short',
+ uint => 'unsigned int',
+ ulong => 'unsigned long',
+ float => 'float',
+ double => 'double',
+ longdouble => 'long double',
+ Parrot_Int1 => 'char',
+ Parrot_Int2 => 'short',
+ Parrot_Int4 => 'int',
+ Parrot_Int8 => 'long long',
+ charptr => 'char *',
+ voidptr => 'void *',
+ funcptr_t => 'funcptr_t',
+
+ longlong => 'long long',
+ ulonglong => 'unsigned long long',
+ __float128 => '__float128',
+ );
+
+ my $alignof = '';
+ for my $name (keys %types) {
+ my $type = $types{$name};
+ my $value = test_alignof($conf, $name, $type);
+ $alignof .= ' '.$name;
+ if ($value) {
+ $conf->data->set( 'PARROT_ALIGNOF_'.$name => $value );
+ }
+ }
+ $conf->data->set( 'alignof' => $alignof );
+
+ return 1;
+}
+
+#################### INTERNAL SUBROUTINES ####################
+
+sub test_alignof {
+ my ($conf, $name, $type) = @_;
+
+ $conf->data->set( TEMP_type => $type );
+ my ($cc_inc, $ccflags) = $conf->data->get( 'cc_inc', 'ccflags' );
+ $conf->cc_gen('config/auto/alignof/test_c.in');
+ eval { $conf->cc_build("$cc_inc -x c++") };
+ my $ret = $@ ? 0 : eval $conf->cc_run();
+ # $conf->cc_clean();
+
+ return $ret;
+}
+
+1;
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
View
53 config/auto/alignof/test_c.in
@@ -0,0 +1,53 @@
+/*
+Copyright (C) 2012, Parrot Foundation.
+
+figure out some Configure settings
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+struct PMC {
+ unsigned int flags;
+ void *vtable;
+ void *data;
+ PMC *_metadata;
+};
+struct parrot_string_t {
+ unsigned int flags;
+ void * _bufstart;
+ size_t _buflen;
+ char *strstart;
+ unsigned int bufused;
+ unsigned int strlen;
+ unsigned int hashval;
+ const struct PMC *encoding;
+};
+typedef struct PMC PMC;
+typedef struct parrot_string_t STRING;
+typedef void (*funcptr_t)(void);
+
+typedef struct {char c; @TEMP_type@ d;} mystruct_t;
+
+
+/* from parrot.h:
+ * some SGI compilers have an offsetof()
+ * definition that doesn't work for us. */
+#if defined(__sgi) && defined(_COMPILER_VERSION) && (_COMPILER_VERSION >= 400)
+# undef offsetof
+# define offsetof(s, m) (size_t)(&((((s) *)0)->(m)))
+#endif
+
+int
+main(int argc, char **argv)
+{
+ printf("%u\n", (unsigned)offsetof(mystruct_t, d));
+ return EXIT_SUCCESS;
+}
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+ */
View
4 lib/Parrot/Configure/Step/List.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2010, Parrot Foundation.
+# Copyright (C) 2001-2012, Parrot Foundation.
package Parrot::Configure::Step::List;
use strict;
use warnings;
@@ -39,7 +39,6 @@ my @steps = qw(
auto::inline
auto::gc
auto::memalign
- auto::alignof
auto::signal
auto::socklen_t
auto::stat
@@ -64,6 +63,7 @@ my @steps = qw(
auto::libffi
auto::ipv6
auto::platform
+ auto::alignof
gen::config_h
gen::core_pmcs
gen::opengl
Please sign in to comment.
Something went wrong with that request. Please try again.