home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.parl.clemson.edu
/
2015-02-07.ftp.parl.clemson.edu.tar
/
ftp.parl.clemson.edu
/
pub
/
coven
/
coven-utils-1.1.tgz
/
coven-utils-1.1.tar
/
utils
/
coven-language
/
outgen.c
< prev
next >
Wrap
C/C++ Source or Header
|
2003-01-28
|
4KB
|
168 lines
/*
* (C) 2001 Clemson University
*
* See COPYING in top-level directory.
*/
#include <stdio.h>
#include <Coven_lang.h>
#include <symbol.h>
void output_begin()
{
fprintf(out_file, "#include \"coven.h\"\n\n");
}
void output_begin_mod_decls()
{
fprintf(out_file,"struct COVEN_Mod_Decl _coven_mod_decl_array[] = {\n");
}
void output_mod_decl (sym_ent_p mod)
{
fprintf(out_file," {\n"
" %s, \n"
" \"%s\"\n"
" },\n", mod->value.mod->path,
mod->name);
}
void output_end_mod_decls(int num_mods)
{
fprintf(out_file,"};\n\n"
"struct COVEN_Mods _coven_mods = {\n"
" %d, _coven_mod_decl_array\n"
"};\n\n", num_mods);
}
void output_begin_const_decls()
{
fprintf(out_file,"struct COVEN_Const_Decl _coven_constant_array[] = "
"{\n");
}
void output_const_decl(sym_ent_p con)
{
char ct[64];
if(!strcmp(con->value.con->type->name, "int")) {
snprintf(ct, 64, "COVEN_INT");
}
else if(!strcmp(con->value.con->type->name, "float")) {
snprintf(ct, 64, "COVEN_FLOAT");
}
else if(!strcmp(con->value.con->type->name, "double")) {
snprintf(ct, 64, "COVEN_DOUBLE");
}
else if(!strcmp(con->value.con->type->name, "string")) {
snprintf(ct, 64, "COVEN_STRING");
}
else
yyerror("CRAP, can't handle this type yet. :(\n");
fprintf(out_file," {%s, \"%s\", \"%s\"},\n", ct,
con->name, con->value.con->cvalue);
}
void output_end_const_decls(int num_consts)
{
fprintf(out_file,"};\n\n"
"struct COVEN_Consts _coven_constants = {\n"
" %d, \n"
" _coven_constant_array\n"
"};\n\n", num_consts);
}
void output_start_mod_call(sym_ent_p sym)
{
fprintf(out_file,"struct COVEN_Mod_Binding _%s_%d_array[] = {\n",
sym->name, sym->value.mod->times_called);
}
void output_end_mod_call(sym_ent_p sym)
{
/* count how many args this module has, there should be a better
* way to do this, perhaps we should store it */
int num_args = 0;
sym_ent_p cur = sym->value.mod->args;
while(cur != NULL) {
cur = cur->next;
num_args++;
}
fprintf(out_file,"};\n\n"
"struct COVEN_Mod_Binding_Table _%s_%d = {\n"
" %d,\n"
" 0,\n"
" _%s_%d_array\n"
"};\n\n",
sym->name, sym->value.mod->times_called, num_args,
sym->name, sym->value.mod->times_called);
}
void output_mod_binding(sym_ent_p sym, int arg_num, char *global_binding)
{
char *local_binding;
sym_ent_p cur = sym->value.mod->args;
int cur_arg = 0;
while(cur != NULL && cur_arg != arg_num) {
cur_arg++;
cur = cur->next;
}
/* cur should now be pointing to our local binding symbol */
if(cur == NULL) {
yyerror("parser error - argument disappeared.\n");
}
local_binding = cur->name;
fprintf(out_file," {\"%s\", \"%s\"},\n",
local_binding, global_binding);
}
void output_all_mod_calls(mod_call_p first_call)
{
mod_call_p cur = first_call;
int num_calls = 0;
fprintf(out_file,"struct COVEN_Mod_Call _coven_mod_call_array[] = {\n");
while(cur != NULL) {
fprintf(out_file," {\"%s\", %s, %d, %s, %s},\n",
cur->name, cur->proc, cur->thread, cur->btable,
cur->loop);
cur = cur->next;
num_calls++;
}
fprintf(out_file,"};\n\n");
fprintf(out_file,"struct COVEN_Mod_Calls _coven_mod_calls = {\n"
" %d,\n"
" _coven_mod_call_array,\n"
"};\n\n", num_calls);
}
void output_loop(int loop_num, char *loop_tag, int initial_val, char *cmp_type,
char *cmp_tag, int incr_val, int begin_mod, int end_mod)
{
fprintf(out_file,"struct COVEN_Loop _coven_loop_%d = {\n"
" \"%s\",\n"
" %d,\n"
" %s,\n"
" \"%s\",\n"
" %d,\n"
" %d,\n"
" %d,\n"
"};\n\n",
loop_num, loop_tag, initial_val, cmp_type, cmp_tag,
incr_val, begin_mod, end_mod);
}
void output_program(int nmt, int nst)
{
fprintf(out_file,"struct COVEN_Program _coven_program = {\n"
" %d,\n"
" %d,\n"
" &_coven_constants,\n"
" &_coven_mods,\n"
" &_coven_mod_calls,\n"
"};\n", nmt, nst);
}