Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ lib
*.o
*.a
*.class
*.jar
19 changes: 12 additions & 7 deletions analyze/aps-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,44 @@
#include "aps-ag.h"

static int aps_error_count = 0;


void aps_clear_errors()
{
aps_error_count = 0;
}

void aps_error(const void *tnode, const char *fmt, ...)
{
va_list args;
va_start(args,fmt);

fflush(stdout);

(void) fprintf(stderr, "%s.aps:%d:",
aps_yyfilename,tnode_line_number(tnode));
(void) vfprintf(stderr, fmt, args);
(void) fprintf(stderr, "\n");
(void) fflush(stderr);

va_end(args);
++aps_error_count;
}
}

void aps_warning(const void *tnode, const char *fmt, ...)
{
va_list args;
va_start(args,fmt);

fflush(stdout);

(void) fprintf(stderr, "%s.aps:%d:Warning: ",
aps_yyfilename,tnode_line_number(tnode));
(void) vfprintf(stderr, fmt, args);
(void) fprintf(stderr, "\n");
(void) fflush(stderr);

va_end(args);
}
}

void aps_check_error(const char *type)
{
Expand Down
1 change: 1 addition & 0 deletions analyze/aps-debug.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef APS_DEBUG_H

extern void aps_clear_errors();
extern void aps_error(const void *tnode, const char *fmt, ...);
extern void aps_warning(const void *tnode, const char *fmt, ...);
extern void aps_check_error(const char *type); // exit if errors due to type
Expand Down
83 changes: 57 additions & 26 deletions aps2scala/aps2scala.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>
#include <cstring>
#include <strings.h>
#include "aps-ag.h"
Expand Down Expand Up @@ -38,69 +39,99 @@ extern void init_lexer(FILE*);
extern int aps_yyparse(void);
}

Implementation* impl;
Implementation* impl = dynamic_impl;
bool static_schedule = 0;
int i = 1;
int argc;
char **argv;

int main(int argc,char **argv) {
argv0 = argv[0];
if (argc < 2) usage();
for (int i=1; i < argc; ++i) {
void process_next_arg();
void process_arg();

void handle_signal(int signal_num) {
if (signal_num == SIGABRT) {
cout << "Static scheduler failed, falling back to dynamic" << endl;
aps_clear_errors();
impl = dynamic_impl;
process_arg();
}
}


void process_arg() {
if (streq(argv[i],"--omit")) {
omit_declaration(argv[++i]);
continue;
process_next_arg();
} else if (streq(argv[i],"--impl")) {
impl_module(argv[i+1],argv[i+2]);
i += 2;
continue;
process_next_arg();
} else if (streq(argv[i],"-I") || streq(argv[i],"--incremental")) {
incremental = true;
continue;
process_next_arg();
} else if (streq(argv[i],"-S") || streq(argv[i],"--static")) {
static_schedule = true;
continue;
impl = static_impl;
if (!impl) {
cerr << "Warning: static scheduling not implemented: reverting to dynamic..." << endl;
impl = dynamic_impl;
}
process_next_arg();
} else if (streq(argv[i],"-V") || streq(argv[i],"--verbose")) {
++verbose;
continue;
process_next_arg();
} else if (streq(argv[i],"-G") || streq(argv[i],"--debug")) {
++debug;
continue;
process_next_arg();
} else if (streq(argv[i],"-p") || streq(argv[i],"--apspath")) {
set_aps_path(argv[++i]);
continue;
process_next_arg();
} else if (argv[i][0] == '-' && argv[i][1] == 'D') {
set_debug_flags(argv[i]+2);
continue;
process_next_arg();
} else if (argv[i][0] == '-') {
usage();
}

Program p = find_Program(make_string(argv[i]));
if (p == 0) {
fprintf(stderr,"Cannot find APS compilation unit %s\n",argv[i]);
continue;


}
aps_check_error("parse");
aps_yyfilename = (char*)program_name(p);
bind_Program(p);
aps_check_error("binding");
type_Program(p);
aps_check_error("type");
if (static_schedule) {
impl = static_impl;

if (impl == static_impl) {
signal(SIGABRT, &handle_signal);
analyze_Program(p);
aps_check_error("analysis");
if (!impl) {
cerr << "Warning: static scheduling not implemented: reverting to dynamic..." << endl;
impl = dynamic_impl;
}
} else {
impl = dynamic_impl;
}
char* outfilename = str2cat(argv[i],".scala");

char* outfilename = str2cat(argv[i],".scala");
ofstream out(outfilename);
dump_scala_Program(p,out);
}
exit(0);
process_next_arg();
}

void process_next_arg() {
i++;
if (i < argc) {
process_arg();
} else {
exit(0);
}
}

int main(int c,char **v) {
argc = c;
argv = v;
argv0 = argv[0];
if (argc < 2) usage();
process_arg();
}


Expand Down
14 changes: 7 additions & 7 deletions examples/scala/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ APSLIB = ${APSTOP}/lib/aps-library-${SCALAV}.jar
SCALAFLAGS= -cp .:${APSLIB}
SCALACFLAGS= ${SCALAFLAGS}
APS2SCALA = ${APSTOP}/bin/aps2scala
APS2SCALAFLAGS = -p ..:${APSTOP}/base -G
APS2SCALAFLAGS = -p ..:${APSTOP}/base -G -S

SCALAGEN = simple.scala classic-binding.scala tiny.scala \
test-coll.scala test-use-coll.scala test-cycle.scala use-global.scala
test-coll.scala test-use-coll.scala test-cycle.scala use-global.scala

.PHONY: all clean

all : ${SCALAGEN}
all : simple_implicit.class classic_binding_implicit.class Classic.class
all : test_coll_implicit.class TestCollDriver.class
all : test_cycle_implicit.class TestCycleDriver.class
all : test_use_coll_implicit.class TestUseCollDriver.class
all : Classic.class
all : TestCollDriver.class
all : TestCycleDriver.class
all : TestUseCollDriver.class

.PHONY: run

Expand Down Expand Up @@ -46,7 +46,7 @@ test_use_coll_implicit.class : test-use-coll.scala
TestCollDriver.class : test_coll_implicit.class test-coll-driver.scala
${SCALAC} ${SCALACFLAGS} test-coll-driver.scala

TestUseCollDriver.class : test_use_coll_implicit.class test-use-coll-driver.scala tiny_implicit.class
TestUseCollDriver.class : tiny_implicit.class test_use_coll_implicit.class test-use-coll-driver.scala
${SCALAC} ${SCALACFLAGS} test-use-coll-driver.scala

test_cycle_implicit.class : test-cycle.scala
Expand Down