Skip to content

Commit

Permalink
[c99] Relocating c99 language to languages repository from
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonrandal committed Mar 10, 2009
0 parents commit f1c2b76
Show file tree
Hide file tree
Showing 26 changed files with 4,213 additions and 0 deletions.
7 changes: 7 additions & 0 deletions MAINTAINER
@@ -0,0 +1,7 @@
# $Id: MAINTAINER 25984 2008-02-22 12:18:20Z kjs $

N: Kevin Tew
E: kevintew@tewk.com

N: Klaas-Jan Stol (kjs)
E: parrotcode@gmail.com
80 changes: 80 additions & 0 deletions c99.pir
@@ -0,0 +1,80 @@
# $Id: c99.pir 36833 2009-02-17 20:09:26Z allison $
# Copyright (C) 2008, Parrot Foundation.

=head1 TITLE

c99.pir - A C99 compiler.

=head2 Description

This is the base file for the C99 compiler.

This file includes the parsing and grammar rules from
the src/ directory, loads the relevant PGE libraries,
and registers the compiler under the name 'C99'.

=head2 Functions

=over 4

=item onload()

Creates the C compiler using a C<PCT::HLLCompiler>
object.

=cut

.namespace [ 'C99';'Compiler' ]

.loadlib 'c99_group'

.sub 'onload' :anon :load :init
load_bytecode 'PCT.pbc'

$P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = $P0.'new'()
$P1.'language'('C99')
$P1.'parsegrammar'('C99::Grammar')
$P1.'parseactions'('C99::Grammar::Actions')
.end
=item main(args :slurpy) :main
Start compilation by passing any command line C<args>
to the C compiler.
=cut
.sub 'main' :main
.param pmc args
$P0 = compreg 'C99'
$P1 = $P0.'command_line'(args)
.end
.include 'src/gen_builtins.pir'
.include 'src/gen_grammar.pir'
.include 'src/gen_actions.pir'
.namespace [ 'C99';'Grammar' ]
.sub 'debug'
.param pmc match
.param pmc arg
.param pmc attrs :slurpy
printerr arg
printerr "\n"
.end
=back
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
102 changes: 102 additions & 0 deletions config/makefiles/cpp.in
@@ -0,0 +1,102 @@
# Copyright (C) 2008-2009, Parrot Foundation.
## $Id: cpp.in 36833 2009-02-17 20:09:26Z allison $

## arguments we want to run parrot with
PARROT_ARGS =

## configuration settings
BUILD_DIR = @build_dir@
LOAD_EXT = @load_ext@
O = @o@

## Setup some commands
PERL = @perl@
RM_F = @rm_f@
CP = @cp@
CAT = @cat@
PARROT = ../../../../parrot@exe@
BUILD_DYNPMC = $(PERL) $(BUILD_DIR)/tools/build/dynpmc.pl
RECONFIGURE = $(PERL) $(BUILD_DIR)/tools/dev/reconfigure.pl

## places to look for things
PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext
PGE_LIBRARY = $(BUILD_DIR)/runtime/parrot/library/PGE
PERL6GRAMMAR = $(PGE_LIBRARY)/Perl6Grammar.pbc
NQP = $(BUILD_DIR)/compilers/nqp/nqp.pbc
PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc

PMC_DIR = src/pmc

all: cpp.pbc

SOURCES = cpp.pir \
src/gen_grammar.pir \
src/gen_actions.pir \
src/gen_builtins.pir

BUILTINS_PIR = \
src/builtins/say.pir

# the default target
cpp.pbc: $(PARROT) $(SOURCES)
$(PARROT) $(PARROT_ARGS) -o cpp.pbc cpp.pir
$(CP) cpp.pbc ../../cpp.pbc

src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg
$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
--output=src/gen_grammar.pir \
src/parser/grammar.pg

src/gen_actions.pir: $(NQP) $(PCT) src/parser/actions.pm
$(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
--target=pir src/parser/actions.pm

src/gen_builtins.pir: $(BUILTINS_PIR)
$(CAT) $(BUILTINS_PIR) >src/gen_builtins.pir

# regenerate the Makefile
Makefile: ../../config/makefiles/cpp.in
cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=c99

# This is a listing of all targets, that are meant to be called by users
help:
@echo ""
@echo "Following targets are available for the user:"
@echo ""
@echo " all: c.pbc"
@echo " This is the default."
@echo "Testing:"
@echo " test: Run the test suite."
@echo " testclean: Clean up test results."
@echo ""
@echo "Cleaning:"
@echo " clean: Basic cleaning up."
@echo " realclean: Removes also files generated by 'Configure.pl'"
@echo " distclean: Removes also anything built, in theory"
@echo ""
@echo "Misc:"
@echo " help: Print this help message."
@echo ""

test: all
$(PERL) t/harness

# this target has nothing to do
testclean:

CLEANUPS = \
cpp.pbc \
"src/gen_*.pir"

clean:
$(RM_F) $(CLEANUPS)

realclean: clean
$(RM_F) Makefile

distclean: realclean

# Local variables:
# mode: makefile
# End:
# vim: ft=make:
113 changes: 113 additions & 0 deletions config/makefiles/root.in
@@ -0,0 +1,113 @@
# Copyright (C) 2006-2009, Parrot Foundation.
## $Id: root.in 36833 2009-02-17 20:09:26Z allison $

## arguments we want to run parrot with
PARROT_ARGS =

## configuration settings
BUILD_DIR = @build_dir@
LOAD_EXT = @load_ext@
O = @o@

## Setup some commands
PERL = @perl@
RM_RF = @rm_rf@
CP = @cp@
CAT = @cat@
MAKE = @make_c@
PARROT = ../../parrot@exe@
BUILD_DYNPMC = $(PERL) $(BUILD_DIR)/tools/build/dynpmc.pl
RECONFIGURE = $(PERL) $(BUILD_DIR)/tools/dev/reconfigure.pl
#IF(darwin):
#IF(darwin):# MACOSX_DEPLOYMENT_TARGET must be defined for OS X compilation/linking
#IF(darwin):export MACOSX_DEPLOYMENT_TARGET := @osx_version@

## places to look for things
PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext
PGE_LIBRARY = $(BUILD_DIR)/runtime/parrot/library/PGE
PERL6GRAMMAR = $(PGE_LIBRARY)/Perl6Grammar.pbc
NQP = $(BUILD_DIR)/compilers/nqp/nqp.pbc
PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc

PMC_DIR = src/pmc

all: c99.pbc cpp

C_GROUP = $(PMC_DIR)/c_group$(LOAD_EXT)

SOURCES = c99.pir \
src/gen_grammar.pir \
src/gen_actions.pir \
src/gen_builtins.pir

BUILTINS_PIR = \
src/builtins/say.pir

c99.pbc: $(PARROT) $(SOURCES)
$(PARROT) $(PARROT_ARGS) -o c99.pbc c99.pir

src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg
$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
--output=src/gen_grammar.pir \
src/parser/grammar.pg

src/gen_actions.pir: $(NQP) $(PCT) src/parser/actions.pm
$(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
--target=pir src/parser/actions.pm

src/gen_builtins.pir: $(BUILTINS_PIR)
$(CAT) $(BUILTINS_PIR) >src/gen_builtins.pir

cpp:
$(MAKE) src/cpp

# regenerate the Makefile
Makefile: config/makefiles/root.in
cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=c99

# This is a listing of all targets, that are meant to be called by users
help:
@echo ""
@echo "Following targets are available for the user:"
@echo ""
@echo " all: c.pbc"
@echo " This is the default."
@echo "Testing:"
@echo " test: Run the test suite."
@echo " testclean: Clean up test results."
@echo ""
@echo "Cleaning:"
@echo " clean: Basic cleaning up."
@echo " realclean: Removes also files generated by 'Configure.pl'"
@echo " distclean: Removes also anything built, in theory"
@echo ""
@echo "Misc:"
@echo " help: Print this help message."
@echo ""

test: all
$(PERL) t/harness
$(MAKE) src/cpp test

# this target has nothing to do
testclean:

CLEANUPS = \
c99.pbc \
"src/gen_*.pir"

clean:
$(RM_RF) $(CLEANUPS)
$(MAKE) src/cpp clean

realclean: clean
$(RM_RF) Makefile
$(MAKE) src/cpp realclean

distclean: realclean
$(MAKE) src/cpp distclean

# Local variables:
# mode: makefile
# End:
# vim: ft=make:
90 changes: 90 additions & 0 deletions lib/Parrot/Test/C99.pm
@@ -0,0 +1,90 @@
# $Id: C99.pm 36833 2009-02-17 20:09:26Z allison $
# Copyright (C) 2006, Parrot Foundation.


package Parrot::Test::C99;

use strict;
use warnings;

use File::Basename;

=head1 Parrot::Test::C99
Provide language specific testing routines here...
This is currently alarmingly similar to the generated subs in Parrot::Test.
Perhaps someone can do a better job of delegation here.
=cut

sub new {
return bless {};
}

sub output_is() {
my ( $self, $code, $output, $desc ) = @_;

#print "@_\n";

my $count = $self->{builder}->current_test + 1;
$desc = 'C99 Test' unless $desc;

my $lang_f = File::Spec->rel2abs( Parrot::Test::per_test( '.c', $count ) );
my $out_f = File::Spec->rel2abs( Parrot::Test::per_test( '.out', $count ) );
my $c99_out_f = File::Spec->rel2abs( Parrot::Test::per_test( '.c99.out', $count ) );
my $c99_out_debug_f = File::Spec->rel2abs( Parrot::Test::per_test( '.c99.debug.out', $count ) );
my $parrotdir = dirname $self->{parrot};

Parrot::Test::write_code_to_file( $code, $lang_f );

my $args = $ENV{TEST_PROG_ARGS} || '';

#my $gcc_cmd = "gcc $lang_f";
#my $gcc_exit_code = Parrot::Test::run_command($gcc_cmd, CD => $self->{relpath}, STDOUT => $out_f, STDERR => $out_f );
#my $gcc_output = Parrot::Test::slurp_file($out_f);

my $c99_cmd = "$self->{parrot} $args languages/c99/c99.pbc $lang_f";
my $c99_exit_code = Parrot::Test::run_command(
$c99_cmd,
CD => $self->{relpath},
STDOUT => $c99_out_f,
STDERR => $c99_out_f
);
my $c99_output = Parrot::Test::slurp_file($c99_out_f);

my $pass = $self->{builder}->is_eq( $c99_output, "1" );

#my $pass = $self->{builder}->is_eq( $c99_output, $gcc_output, $desc );
#$self->{builder}->diag("'$gcc_cmd' failed with exit code $gcc_exit_code") if $gcc_exit_code and not $pass;
$self->{builder}->diag("'$c99_cmd' failed with exit code $c99_exit_code")
if $c99_exit_code and not $pass;

if ( not $pass ) {
my $c99_debug_cmd = "$self->{parrot} $args languages/c99/c99.pbc -d $lang_f";
my $c99_debug_exit_code = Parrot::Test::run_command(
$c99_debug_cmd,
CD => $self->{relpath},
STDOUT => $c99_out_debug_f,
STDERR => $c99_out_debug_f
);
my $c99_debug_output = Parrot::Test::slurp_file($c99_out_debug_f);
}

unless ( $ENV{POSTMORTEM} ) {

#unlink $lang_f;
unlink $out_f;
unlink $c99_out_f;
}
return $pass;
}

1;

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

0 comments on commit f1c2b76

Please sign in to comment.