Commit 457e69b2 authored by rdubner's avatar rdubner
Browse files

cobst creates <program>.sym.c files

parent 539bbedf
......@@ -227,9 +227,10 @@ void CreateFullCSV(PARAMETERS &params,
csv.Generate(params.full_csv);
}
void CreateCSV(PARAMETERS &params,
const COB_LABELS &cob_labels,
const VARIABLE_TREE &var_tree)
static void
CreateCSV(PARAMETERS &params,
const COB_LABELS &cob_labels,
const VARIABLE_TREE &var_tree)
{
/* This file, originally designed to be a .CSV file, hence the
function name, and now a tab-delineated file, contains the
......@@ -411,6 +412,72 @@ void CreateCSV(PARAMETERS &params,
csv.Generate(params.csv);
}
static void
CreateCModule(PARAMETERS &params,
const VARIABLE_TREE &var_tree)
{
/* This routine puts the COBOL-identifier/C-identifier cross-reference
information into a .c module destined to be compiled and linked into
the the executable.
*/
params.csym << "// COBOL-to-C symbol cross reference, generated by \n";
params.csym << "// the COBST program.\n";
params.csym << "// For safety's sake, compile with -O0 'no optimization' switch\n";
params.csym << endl;
params.csym << "typedef struct" << endl;
params.csym << " {" << endl;
params.csym << " char const * const p;" << endl;
params.csym << " } ENTRY;" << endl;
params.csym << endl;
// Build an oddball name, to zeroize collision possibilities
params.csym << "volatile ENTRY " << params.cbl_filename.GetFname()
<< "_o0O0o_Symbols[] = {" << endl;
// You can't change the order of things here unless you also change
// the ordering in cprint.py They are tightly linked, and that's that!
for(int i=0; i<var_tree.size(); i++) {
const VAR_NODE var = var_tree[i];
stringstream ss;
ss << var.GetSection().substr(0,2) << "|";
ss << var.GetLevel() << "|" ;
ss << var.GetCanonicalName() << "|" ;
ss << var.GetBaseSymbol() << "|" ;
ss << var.GetOffset() << "|" ;
ss << var.GetType().substr(0,1) << "|" ;
ss << var.GetSize() << "|" ;
ss << var.GetPicture() << "|" ;
ss << var.GetOccurs() << "|" ;
ss << var.GetFieldSize() << "|" ;
ss << var.GetAttrType() << "|" ;
ss << var.GetAttrDigits() << "|" ;
ss << var.GetAttrScale() << "|" ;
ss << var.GetAttrFlags() << "|";
// To save bytes, let's assume that any "||" will be interpreted as
// being the same as "|0|"
string s = ss.str();
for(;;) {
size_t n = s.find("|0|");
if( n EQ string::npos ) {
break;
}
s.replace(n,3,"||");
}
params.csym << " ENTRY{\"" << s << "\"}," << endl;
}
params.csym << " ENTRY{NULL}" << endl;
params.csym << " };" << endl;
params.csym << endl;
}
int main(int argc, char *argv[])
{
PROFILER;
......@@ -499,5 +566,9 @@ int main(int argc, char *argv[])
// Create our actual useful .TAB file.
CreateCSV(params,cob_labels,variable_tree);
// Create our C-code cross-reference module
CreateCModule(params,variable_tree);
return 0;
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>../samples/cpytest/cpytest.cbl</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>../samples/NC101A/NC101A.cbl</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>../samples/cpytest/cpytest.cbl</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>../samples/NC101A/NC101A.cbl</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>../samples/cpytest/cpytest.cbl</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>../samples/NC101A/NC101A.cbl</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>../samples/cpytest/cpytest.cbl</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>../samples/NC101A/NC101A.cbl</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -234,6 +234,7 @@ PARAMETERS GetParameters(int argc, char *argv[])
retval.cbl_lst_filename.Decode(retval.cbl_filename.Stem() + ".cbl.lst");
retval.full_csv_filename.Decode(retval.cbl_filename.Stem() + ".full.tab");
retval.csv_filename.Decode(retval.cbl_filename.Stem() + ".tab");
retval.csym_filename.Decode(retval.cbl_filename.Stem() + ".sym.c");
OpenOrFail(retval.cbl,retval.cbl_filename.WholePath());
OpenOrFail(retval.i,retval.i_filename.WholePath());
......@@ -242,6 +243,7 @@ PARAMETERS GetParameters(int argc, char *argv[])
OpenOrFail(retval.cbl_lst,retval.cbl_lst_filename.WholePath());
OpenOrFail(retval.full_csv,retval.full_csv_filename.WholePath());
OpenOrFail(retval.csv,retval.csv_filename.WholePath());
OpenOrFail(retval.csym,retval.csym_filename.WholePath());
return retval;
}
......
......@@ -3,7 +3,7 @@
#include <string>
#include <fstream>
#define VERSION "0.9.1"
#define VERSION "0.10.1"
class FILENAME
{
......@@ -74,25 +74,28 @@ public:
FILENAME cbl_filename; // Original COBOL source code
FILENAME cbl_lst_filename; // GnucCOBOL-generated stylized source code,
// with parsed STORAGE sections
// // with parsed STORAGE sections
FILENAME i_filename; // intermediate COBOL source code file
// generated by GnuCOBOL
// // generated by GnuCOBOL
FILENAME c_filename; // intermediate C source code file
// generated by GnuCOBOL
// // generated by GnuCOBOL
FILENAME lst_filename; // Mixed C/assembler listing file generated
// by GAS assembler when gcc processes c_filename
// // by GAS assembler when gcc processes c_filename
FILENAME full_csv_filename; // Our original output file, with everything
// we know in it.
// // we know in it.
FILENAME csv_filename; // Our output file, destined to be read
// downstream
// // downstream
FILENAME csym_filename; // Our output file, destined to be
// // compiled into the executable
std::ifstream cbl; // Streams for the above files
std::ifstream cbl; // Streams for the above files
std::ifstream cbl_lst;
std::ifstream i;
std::ifstream c;
std::ifstream lst;
std::ofstream full_csv;
std::ofstream csv;
std::ofstream csym;
bool quiet;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment