Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
251abb6
Farrow Live Variable analysis + lexer/parser
amir734jj Jun 5, 2024
f5e4705
Used GCD program to make it more interesting
amir734jj Jun 7, 2024
d912f9d
WIP on UBD
amir734jj Jun 9, 2024
952a640
wip
amir734jj Jul 3, 2024
49eed07
Farrow's use-before-declaration
amir734jj Jul 15, 2024
251bd45
Merge remote-tracking branch 'origin/master' into user/amir734jj/farr…
amir734jj Jul 15, 2024
9ba24b1
newline at the end to make github happy
amir734jj Jul 15, 2024
67d7360
Revert a change for this PR
amir734jj Jul 15, 2024
1225490
small bug in the APS file
amir734jj Jul 15, 2024
b698d38
first working step
amir734jj Sep 8, 2024
b7d92d9
improvement to simple-snc
amir734jj Sep 8, 2024
ee07a6e
fixed start of synth eval
amir734jj Sep 8, 2024
231721e
a lot of bad code
amir734jj Sep 8, 2024
2b7e9db
fixed the bug
amir734jj Sep 26, 2024
2ded648
working simple snc
amir734jj Sep 27, 2024
7c0da99
more progress
amir734jj Oct 19, 2024
5c0ed66
initial working state
amir734jj Jun 8, 2025
36efc4b
APS code for farrow's example improvement
amir734jj Jun 8, 2025
edb6b7e
small fix ups
amir734jj Jun 8, 2025
fc49520
small changes found by Prof. Boyland
amir734jj Jun 11, 2025
b09e203
added check to make sure when scheduling dependency fails/succeeds
amir734jj Jun 16, 2025
7324bb8
revert space changes
amir734jj Jun 16, 2025
bb39cb8
small revert
amir734jj Jun 16, 2025
4b5fa92
wip
amir734jj Sep 6, 2025
21f88d1
small improvements
amir734jj Nov 9, 2025
830b9f0
regular cleanups
amir734jj Nov 9, 2025
4cdf61b
comment fixes
amir734jj Nov 9, 2025
6f1b6bc
Refactor Makefile to use DEBUG_FLAGS variable
amir734jj Nov 13, 2025
2cf6707
partial commit
amir734jj Nov 10, 2025
3de6e2a
partial commit
amir734jj Jan 20, 2026
b308bb4
fix errors in test files
amir734jj Jan 20, 2026
282cfe6
Merge remote-tracking branch 'boyland/master' into user/amir734jj/syn…
amir734jj Jan 20, 2026
3ca680e
Merge branch 'user/amir734jj/synth-functions' of https://github.com/a…
amir734jj Jan 20, 2026
7145791
Revert unnessary changes
amir734jj Jan 20, 2026
76a9158
hacky farrow's lv working
amir734jj Jan 21, 2026
49a986f
making progress
amir734jj Jan 30, 2026
376a1be
small bug fixes
amir734jj Feb 24, 2026
e8f8c9f
small improvement
amir734jj Mar 20, 2026
7efcefc
wip
amir734jj Mar 20, 2026
47779bf
wip
amir734jj Mar 20, 2026
602f101
more improvements
shesamian Mar 20, 2026
3b3220a
Merge branch 'user/amir734jj/synth-functions' of https://github.com/a…
amir734jj Mar 20, 2026
149632f
needs a overehaul
amir734jj Mar 20, 2026
4429809
not sure
shesamian Mar 20, 2026
1bcb559
missing default handled
amir734jj Mar 21, 2026
8718dcd
Merge remote-tracking branch 'boyland/master' into user/amir734jj/syn…
amir734jj Mar 21, 2026
d21c477
wip
amir734jj Mar 27, 2026
146e8cb
bug fixes
shesamian Mar 27, 2026
473d75c
wip
shesamian Mar 27, 2026
dfa9ce1
more work needed
amir734jj Mar 28, 2026
28295bc
wip
shesamian Mar 28, 2026
863e788
wip
shesamian Mar 28, 2026
33de0c0
wip
amir734jj Mar 28, 2026
164d561
fix indentations
shesamian Mar 28, 2026
d6964d2
small fixes
amir734jj Mar 28, 2026
c599821
I think its finished
amir734jj Mar 30, 2026
d103940
wip
amir734jj Mar 30, 2026
73bf7a9
wip
shesamian Mar 31, 2026
e8c8a6f
Merge remote-tracking branch 'boyland/master' into user/amir734jj/syn…
shesamian Mar 31, 2026
8f8a770
wip
amir734jj Apr 9, 2026
7f747d2
wip
shesamian Apr 9, 2026
0e0ffcf
print_linearized_block if include comment is true
amir734jj Apr 9, 2026
02f0544
comment improvements
shesamian Apr 9, 2026
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
92 changes: 51 additions & 41 deletions analyze/aps-analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Several phases:

// Boolean indicating whether to use SCC chunk scheduling
bool static_scc_schedule = false;
bool anc_analysis = false;

static void *analyze_thing(void *ignore, void *node)
{
Expand All @@ -29,66 +30,75 @@ static void *analyze_thing(void *ignore, void *node)
{
default: break;
case KEYmodule_decl:
s = compute_dnc(decl);
if (!(d = (s->original_state_dependency = analysis_state_cycle(s))))
{
// Do nothing; no cycle to remove
s->loop_required = false;
}
else if (!(d & DEPENDENCY_MAYBE_SIMPLE) || !(d & DEPENDENCY_NOT_JUST_FIBER))
{
printf("Fiber cycle detected (%d); cycle being removed\n", d);
s = compute_dnc(decl, anc_analysis);
if (anc_analysis) {
if (cycle_debug & PRINT_CYCLE)
{
print_cycles(s, stdout);
}
break_fiber_cycles(decl, s, d);
d = (s->original_state_dependency = analysis_state_cycle(s));
s->loop_required = !(d & DEPENDENCY_MAYBE_SIMPLE);
d = no_dependency; // clear dependency
}
else
{
aps_error(decl, "Unable to handle dependency (%d); Attribute grammar is not DNC", d);
return NULL;
}

// If SCC scheduling is in-progress
if (static_scc_schedule)
{
// Pure fiber cycles should have been broken when reaching this step
// If there is a non-monotone cycle, then scheduling is no longer possible
if (d & DEPENDENCY_MAYBE_SIMPLE)
} else {
if (!(d = (s->original_state_dependency = analysis_state_cycle(s))))
{
// Do nothing; no cycle to remove
s->loop_required = false;
}
else if (!(d & DEPENDENCY_MAYBE_SIMPLE) || !(d & DEPENDENCY_NOT_JUST_FIBER))
{
printf("Fiber cycle detected (%d); cycle being removed\n", d);
if (cycle_debug & PRINT_CYCLE)
{
print_cycles(s, stdout);
}

aps_error(decl, "Non-monotone Cycle detected (%d); Attribute grammar is not COAG", d);
break_fiber_cycles(decl, s, d);
s->loop_required = !(d & DEPENDENCY_MAYBE_SIMPLE);
d = no_dependency; // clear dependency
}
else
{
aps_error(decl, "Unable to handle dependency (%d); Attribute grammar is not DNC", d);
return NULL;
}

// SCC chunk scheduling supports CRAG without conditional cycles
compute_static_schedule(s);
}
else
{
if (!d)
// If SCC scheduling is in-progress
if (static_scc_schedule)
{
// RAG scheduling with conditional cycles
compute_oag(decl, s); // calculate OAG if grammar is DNC
d = analysis_state_cycle(s); // check again for type-3 errors
}
// Pure fiber cycles should have been broken when reaching this step
// If there is a non-monotone cycle, then scheduling is no longer possible
if (d & DEPENDENCY_MAYBE_SIMPLE)
{
if (cycle_debug & PRINT_CYCLE)
{
print_cycles(s, stdout);
}

aps_error(decl, "Non-monotone Cycle detected (%d); Attribute grammar is not COAG", d);
return NULL;
}

if (d)
// SCC chunk scheduling supports CRAG without conditional cycles
compute_static_schedule(s);
}
else
{
if (cycle_debug & PRINT_CYCLE)
if (!d)
{
print_cycles(s, stdout);
// RAG scheduling with conditional cycles
compute_oag(decl, s); // calculate OAG if grammar is DNC
d = analysis_state_cycle(s); // check again for type-3 errors
}

aps_error(decl, "Cycle detected (%d); Attribute grammar is not OAG", d);
return NULL;
if (d)
{
if (cycle_debug & PRINT_CYCLE)
{
print_cycles(s, stdout);
}

aps_error(decl, "Cycle detected (%d); Attribute grammar is not OAG", d);
return NULL;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions analyze/aps-analyze.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(STATE*)(Declaration_info(md)->analysis_state)

extern bool static_scc_schedule;
extern bool anc_analysis;

extern void analyze_Program(Program); /* decorate modules with STATE */

Expand Down
35 changes: 25 additions & 10 deletions analyze/aps-dnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ int analysis_debug = 0;


/*** FUNCTIONS FOR INSTANCES */
BOOL instance_equal(INSTANCE *in1, INSTANCE *in2) {
return in1->node == in2->node && fibered_attr_equal(&in1->fibered_attr, &in2->fibered_attr);
}

BOOL fibered_attr_equal(FIBERED_ATTRIBUTE *fa1, FIBERED_ATTRIBUTE *fa2) {
return fa1->attr == fa2->attr && fa1->fiber == fa2->fiber;
Expand Down Expand Up @@ -677,14 +680,6 @@ static int assign_instances(INSTANCE *array, int index,
return index;
}

static Type infer_some_value_decl_type(Declaration d) {
if (Declaration_KEY(d) == KEYnormal_formal) {
return infer_formal_type(d);
} else {
return some_value_decl_type(d);
}
}

/** Count and then assign instances.
* Called in two cases: <ul>
* <li> one to set instance indices and count instances
Expand Down Expand Up @@ -881,6 +876,7 @@ static void *get_instances(void *vaug_graph, void *node) {
nil_Expressions());
Expression_info(e)->funcall_proxy = proxy;
Declaration_info(proxy)->instance_index = index;
Declaration_info(proxy)->proxy_fdecl = fdecl;
Declaration_info(proxy)->node_phy_graph =
summary_graph_for(s,fdecl);
Declaration_info(proxy)->decl_flags |= DECL_RHS_FLAG;
Expand Down Expand Up @@ -2446,6 +2442,22 @@ static void synchronize_dependency_graphs(AUG_GRAPH *aug_graph,

phy_n = phy_graph->instances.length;

int index_of_lhs = -1;
for (i = 0; i < n; i++) {
if (aug_graph->instances.array[i].node == aug_graph->lhs_decl) {
index_of_lhs = i;
break;
}
}

if (index_of_lhs == -1) {
fatal_error("LHS %d not found in instances of %s", decl_name(aug_graph->lhs_decl), aug_graph_name(aug_graph));
} else {
if (analysis_debug & SUMMARY_EDGE) {
printf("LHS found at index %d for %s\n", index_of_lhs, aug_graph_name(aug_graph));
}
}

/* discover when the instances for this node end.
*/
max = start + phy_n;
Expand Down Expand Up @@ -2515,7 +2527,6 @@ static void augment_dependency_graph_for_node(AUG_GRAPH *aug_graph,
Declaration node) {
int start=Declaration_info(node)->instance_index;
PHY_GRAPH *phy_graph = Declaration_info(node)->node_phy_graph;

synchronize_dependency_graphs(aug_graph,start,phy_graph);
}

Expand Down Expand Up @@ -2832,9 +2843,10 @@ void dnc_close(STATE*s) {
}
}

STATE *compute_dnc(Declaration module) {
STATE *compute_dnc(Declaration module, bool anc_analysis) {
STATE *s=(STATE *)HALLOC(sizeof(STATE));
Declaration_info(module)->analysis_state = s;
s->anc_analysis = anc_analysis;
init_analysis_state(s,module);
dnc_close(s);
if (analysis_debug & (DNC_ITERATE|DNC_FINAL)) {
Expand Down Expand Up @@ -2876,6 +2888,7 @@ void print_dep_vertex(VERTEX *v, FILE *stream)

void print_instance(INSTANCE *i, FILE *stream) {
if (stream == 0) stream = stdout;
fprintf(stream,"[%d]", i->index);
if (i->node != NULL) {
if (ABSTRACT_APS_tnode_phylum(i->node) != KEYDeclaration) {
fprintf(stream,"%d:?<%d>",tnode_line_number(i->node),
Expand Down Expand Up @@ -2920,6 +2933,8 @@ void print_instance(INSTANCE *i, FILE *stream) {
void print_edge_helper(DEPENDENCY kind, CONDITION *cond, FILE* stream) {
if (stream == 0) stream = stdout;

fprintf(stream,"direct");

if (!(kind & SOME_DEPENDENCY))
{
fputc('!',stream); // no-dependency
Expand Down
5 changes: 4 additions & 1 deletion analyze/aps-dnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ typedef struct attribute_instance {
int index;
} INSTANCE;

extern BOOL instance_equal(INSTANCE*, INSTANCE*);

enum instance_direction {instance_local, instance_inward, instance_outward};
enum instance_direction fibered_attr_direction(FIBERED_ATTRIBUTE *fa);
enum instance_direction instance_direction(INSTANCE *);
Expand Down Expand Up @@ -109,6 +111,7 @@ typedef struct analysis_state {
VECTOR(FIBER) fibers;
CYCLES cycles;
BOOL loop_required;
BOOL anc_analysis;
DEPENDENCY original_state_dependency; // This is value of analysis_state_cycle
// before removing fiber cycle or
// linearization of phases in summary graph
Expand All @@ -127,7 +130,7 @@ extern INSTANCE *get_instance(Declaration attr, FIBER fiber,

extern void assert_closed(AUG_GRAPH*);
extern void dnc_close(STATE *);
extern STATE *compute_dnc(Declaration module);
extern STATE *compute_dnc(Declaration module, bool anc_analysis);

/* Low level routines: use with caution */
extern void free_edge(EDGESET old, AUG_GRAPH *aug_graph);
Expand Down
1 change: 1 addition & 0 deletions analyze/aps-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct Declaration_info {
Declaration dual_decl; /* a declaration created out of nowhere */
Declaration copied_decl; /* pointer to copied version (scratch) */
FIBERSETS decl_fibersets;
Declaration proxy_fdecl; /* actual fdecl being proxied */
int if_index; /* count of if_stmt within a top-level match */
#define instance_index if_index
CONDITION decl_cond; /* condition that must be satisfied to take effect */
Expand Down
5 changes: 3 additions & 2 deletions analyze/aps-schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,9 @@ static void print_total_order(AUG_GRAPH* aug_graph,
print_indent(indent, stream);
print_instance(cto->cto_instance, stream);
CONDITION cond = instance_condition(cto->cto_instance);
fprintf(stream, " (visit: %d, component: %d, lineno: %d)", cto->visit,
fprintf(stream, " (visit: %d, component: %d, circular: %s, lineno: %d)", cto->visit,
cto->chunk_index,
cto->chunk_circular ? "circular" : "non-circular",
tnode_line_number(cto->cto_instance->fibered_attr.attr));

if (if_rule_p(cto->cto_instance->fibered_attr.attr)) {
Expand Down Expand Up @@ -2690,7 +2691,7 @@ static ChunkGraph* collect_aug_graph_chunks(AUG_GRAPH* aug_graph,
for (i = 0; i < components->length; i++) {
SCC_COMPONENT* comp = components->array[i];

printf("=> component #%d\n", i);
printf("=> component #%d (%s)\n", i, aug_graph->component_cycle[i] ? "circular" : "non-circular");

for (j = 0; j < comp->length; j++) {
Chunk* chunk = (Chunk*)comp->array[j];
Expand Down
8 changes: 8 additions & 0 deletions analyze/aps-type.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ static Type error_type;

int remote_type_p(Type ty);

Type infer_some_value_decl_type(Declaration d) {
if (Declaration_KEY(d) == KEYnormal_formal) {
return infer_formal_type(d);
} else {
return some_value_decl_type(d);
}
}

Type function_type_return_type(Type ft)
{
return value_decl_type(first_Declaration(function_type_return_values(ft)));
Expand Down
1 change: 1 addition & 0 deletions analyze/aps-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern void check_default_type(Default,Type);
extern void check_matchers_type(Matches,Type);

extern Type infer_formal_type(Declaration formal);
extern Type infer_some_value_decl_type(Declaration d);

/* for the following functions, we don't assume the actuals
* have been checked yet.
Expand Down
3 changes: 3 additions & 0 deletions analyze/apsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void usage() {
fprintf(stderr,"apsc: usage: %s [-DH] [-D...] [-p apspath] file...\n",argv0);
fprintf(stderr," schedule APS files (omit '.aps' extension)\n");
fprintf(stderr," -C SCC chunk static scheduling\n");
fprintf(stderr," -F ANC analysis\n");
fprintf(stderr," -DH print debug options\n");
exit(1);
}
Expand All @@ -26,6 +27,8 @@ int main(int argc,char **argv) {
set_aps_path(argv[++i]);
} else if (*options == 'C') {
static_scc_schedule = true;
} else if (*options == 'F') {
anc_analysis = true;
} else usage();
} else {
Program p = find_Program(make_string(argv[i]));
Expand Down
26 changes: 23 additions & 3 deletions analyze/canonical-type.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#include <stdlib.h>
#include <string.h>
#include "aps-ag.h"
#include "aps-debug.h"
#include "jbb-alloc.h"

static int BUFFER_SIZE = 1000;

/**
* Joins two canonical type
* @param ctype_outer outer canonical type
Expand Down Expand Up @@ -301,7 +304,7 @@ Declaration canonical_type_decl(CanonicalType *canonical_type)
return canonical_qual_use_type->decl;
}
default:
aps_error(canonical_type, "Failed to find the decl for CanonicalType");
aps_error(canonical_type, "Failed to find the decl for CanonicalType key:%d", canonical_type->key);
return NULL;
}
}
Expand Down Expand Up @@ -372,7 +375,7 @@ static CanonicalType *canonical_type_use(Use use)
case KEYfunction_type:
return canonical_type(some_type_decl_type(td));
case KEYremote_type:
return canonical_type(remote_type_nodetype(some_type_decl_type(td)));
return canonical_type(remote_type_nodetype(some_type_decl_type(td)));
default:
fatal_error("Unknown type use_decl type key %d", (int)Type_KEY(some_type_decl_type(td)));
return NULL;
Expand Down Expand Up @@ -726,7 +729,24 @@ static CanonicalType *canonical_type_use_use_join(struct Canonical_use_type *cty
break;
}
default:
fatal_error("Not sure what type of canonical type it is");
{
char outer_type_to_str[BUFFER_SIZE];
char inner_type_to_str[BUFFER_SIZE];
memset(outer_type_to_str, 0, sizeof(outer_type_to_str)); // Ensure null-termination
memset(inner_type_to_str, 0, sizeof(inner_type_to_str)); // Ensure null-termination
FILE *f;

f = fmemopen(outer_type_to_str, sizeof(outer_type_to_str), "w");
print_canonical_type(ctype_outer, f);
fclose(f);

f = fmemopen(inner_type_to_str, sizeof(inner_type_to_str), "w");
print_canonical_type(ctype_inner, f);
fclose(f);

aps_warning(NULL, "Not sure how to handle this type of canonical type while joining use with use %s and %s", outer_type_to_str, inner_type_to_str);
return (CanonicalType *)ctype_inner;
}
}

Declaration decl = ctype_inner->decl;
Expand Down
5 changes: 4 additions & 1 deletion aps2scala/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CPP=g++
CPPFLAGS=-Wall -g -Wno-unused-variable -DUSING_CXX -DAPS2SCALA -I../parse -I../analyze -I../codegen -I../utilities

APS2SCALAOBJS = aps2scala.o dump-scala.o implement.o dyn-impl.o static-impl.o static-scc-impl.o
APS2SCALAOBJS = aps2scala.o dump-scala.o implement.o dyn-impl.o static-impl.o static-scc-impl.o synth-impl.o
APS2SCALALIBS = ../lib/aps-lib.o ../lib/aps-ag.a ../utilities/utilities.o
aps2scala : ${APS2SCALAOBJS} ${APS2SCALALIBS}
${CPP} ${CPPFLAGS} ${APS2SCALAOBJS} ${APS2SCALALIBS} -o aps2scala
Expand All @@ -11,6 +11,9 @@ ${APS2SCALAOBJS} : dump-scala.h
install: aps2scala
mv aps2scala ../bin/.

synth-impl.o : ../codegen/synth-impl.cc
${CPP} -c ${CPPFLAGS} $< -o $@

static-impl.o : ../codegen/static-impl.cc
${CPP} -c ${CPPFLAGS} $< -o $@

Expand Down
Loading