summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2020-04-10 11:45:21 +0000
committerAdrian Thurston <thurston@colm.net>2020-04-10 11:45:21 +0000
commit9760b2b3d8477ffb4228ac3db976e2ed3abb8905 (patch)
treec2b19fe75d3a7101539667d300fb21fd5334e150
parent848214fa4af44056315df6bc34f1fcaccf6d09aa (diff)
downloadcolm-9760b2b3d8477ffb4228ac3db976e2ed3abb8905.tar.gz
making exported vars available from C code
Addes an array of exports to runtime data. Also declares each export as an integer. The value of the export can be passed to colm_get_gloal(). They are named colm_export_<export-name>. refs #116.
-rw-r--r--src/pdabuild.cc30
-rw-r--r--src/pdacodegen.cc22
-rw-r--r--src/pdacodegen.h1
-rw-r--r--src/program.h9
4 files changed, 62 insertions, 0 deletions
diff --git a/src/pdabuild.cc b/src/pdabuild.cc
index 27cd9616..824db1e6 100644
--- a/src/pdabuild.cc
+++ b/src/pdabuild.cc
@@ -1682,6 +1682,36 @@ void Compiler::makeRuntimeData()
runtimeData->global_size = globalObjectDef->size();
/*
+ * Exports.
+ */
+ count = 0;
+ for ( FieldList::Iter of = globalObjectDef->fieldList; of.lte(); of++ ) {
+ ObjectField *field = of->value;
+ if ( field->isExport ) {
+ count += 1;
+ }
+ }
+
+ runtimeData->num_exports = count;
+ if ( count == 0 ) {
+ runtimeData->export_info = 0;
+ }
+ else {
+ runtimeData->export_info = new export_info[count];
+
+ long i = 0;
+ for ( FieldList::Iter of = globalObjectDef->fieldList; of.lte(); of++ ) {
+ ObjectField *field = of->value;
+ if ( field->isExport ) {
+ runtimeData->export_info[i].name = strdup( field->name );
+ runtimeData->export_info[i].global_id = field->offset;
+ i += 1;
+ }
+ }
+ }
+
+
+ /*
* Boundary between terms and non-terms.
*/
runtimeData->first_non_term_id = firstNonTermId;
diff --git a/src/pdacodegen.cc b/src/pdacodegen.cc
index d6435ea9..c96c9afc 100644
--- a/src/pdacodegen.cc
+++ b/src/pdacodegen.cc
@@ -454,6 +454,24 @@ void PdaCodeGen::writeRuntimeData( colm_sections *runtimeData, struct pda_tables
"\n";
out <<
+ "static struct export_info " << exportInfo() << "[] = {\n";
+
+ for ( long i = 0; i < runtimeData->num_exports; i++ ) {
+ out << " { \"" << runtimeData->export_info[i].name << "\", " <<
+ runtimeData->export_info[i].global_id << " },\n";
+ }
+
+ out <<
+ "};\n";
+
+ for ( long i = 0; i < runtimeData->num_exports; i++ ) {
+ out << "const int colm_export_" << runtimeData->export_info[i].name << " = " <<
+ runtimeData->export_info[i].global_id << ";\n";
+ }
+ out <<
+ "\n";
+
+ out <<
"struct colm_sections " << objectName << " = \n"
"{\n"
" " << lelInfo() << ",\n"
@@ -486,6 +504,10 @@ void PdaCodeGen::writeRuntimeData( colm_sections *runtimeData, struct pda_tables
"\n"
" " << genericInfo() << ",\n"
" " << runtimeData->num_generics << ",\n"
+ "\n"
+ " " << exportInfo() << ",\n"
+ " " << runtimeData->num_exports << ",\n"
+ "\n"
" " << runtimeData->argv_generic_id << ",\n"
" " << runtimeData->stds_generic_id << ",\n"
"\n"
diff --git a/src/pdacodegen.h b/src/pdacodegen.h
index 759dd6e0..e965af7d 100644
--- a/src/pdacodegen.h
+++ b/src/pdacodegen.h
@@ -83,6 +83,7 @@ struct PdaCodeGen
String litlen() { return PARSER() + "litlen"; }
String literals() { return PARSER() + "literals"; }
String fsmTables() { return PARSER() + "fsmTables"; }
+ String exportInfo() { return PARSER() + "exportInfo"; }
/*
* Graphviz Generation
diff --git a/src/program.h b/src/program.h
index 8ba716d4..38c505fa 100644
--- a/src/program.h
+++ b/src/program.h
@@ -37,6 +37,12 @@ struct stack_block
struct stack_block *next;
};
+struct export_info
+{
+ const char *name;
+ int global_id;
+};
+
struct colm_sections
{
struct lang_el_info *lel_info;
@@ -70,6 +76,9 @@ struct colm_sections
struct generic_info *generic_info;
long num_generics;
+ struct export_info *export_info;
+ long num_exports;
+
long argv_generic_id;
long stds_generic_id;