Commit 6889ea65 authored by rdubner's avatar rdubner

Modified sfix to compile on RHEL7.

parent 207e8a59
......@@ -28,8 +28,8 @@
#
############################################################################ */
#include <stdlib.h>
#include <iostream>
#include <regex>
#include "params.h"
#include "utils.h"
#ifdef _WIN32
......@@ -221,7 +221,7 @@ Version()
void
OpenOrFail(std::ifstream &ifs,const std::string &fname,std::ios_base::openmode mode/* = std::ifstream::in*/)
{
ifs.open(fname,mode);
ifs.open(fname.c_str(),mode);
if(!ifs.is_open()) {
cerr << "Failed to open input file \"" << fname << "\"" << endl;
exit(1);
......@@ -231,7 +231,7 @@ OpenOrFail(std::ifstream &ifs,const std::string &fname,std::ios_base::openmode m
void
OpenOrFail(std::ofstream &ofs,const std::string &fname,std::ios_base::openmode mode/* = std::ofstream::out*/)
{
ofs.open(fname,mode);
ofs.open(fname.c_str(),mode);
if(!ofs.is_open()) {
cerr << "Failed to open output file \"" << fname << "\"" << endl;
exit(1);
......
......@@ -30,9 +30,11 @@
#include "profiler.h"
#if defined PROFILING
// These are static variables for the PPROFILER class
std::unordered_map<std::string,double> PPROFILER::ProfilerRoutineTimes;
std::unordered_map<std::string,long long> PPROFILER::ProfilerRoutineEntries;
std::map<std::string,double> PPROFILER::ProfilerRoutineTimes;
std::map<std::string,long long> PPROFILER::ProfilerRoutineEntries;
std::vector<double> PPROFILER::AccumulatedTimes;
std::ostream &
......@@ -40,3 +42,5 @@ operator<<(std::ostream &os, PPROFILER const &m)
{
return os << m.Dump();
}
#endif
......@@ -30,8 +30,12 @@
#pragma once
// #define PROFILING
#if defined(PROFILING)
#include <map>
#include <map>
#include <unordered_map>
#include <string>
#include <vector>
#include <chrono>
......@@ -39,13 +43,12 @@
#include <sstream>
#include <algorithm>
// #define PROFILING
class PPROFILER
{
private:
static std::unordered_map<std::string,double> ProfilerRoutineTimes;
static std::unordered_map<std::string,long long> ProfilerRoutineEntries;
static std::map<std::string,double> ProfilerRoutineTimes;
static std::map<std::string,long long> ProfilerRoutineEntries;
static std::vector<double> AccumulatedTimes;
std::string routine;
std::chrono::steady_clock::time_point time_in;
......@@ -141,7 +144,7 @@ public:
size_t max_width = 0;
std::map<std::string,double> smap;
for(std::unordered_map<std::string,double>::const_iterator it=ProfilerRoutineTimes.begin(); it!=ProfilerRoutineTimes.end(); it++) {
for(std::map<std::string,double>::const_iterator it=ProfilerRoutineTimes.begin(); it!=ProfilerRoutineTimes.end(); it++) {
max_width = std::max(max_width,it->first.length());
smap[it->first] = it->second;
}
......@@ -167,6 +170,8 @@ public:
};
#endif
#ifdef PROFILING
#define PROFILER PPROFILER Profiler(__func__);
#define CPROFILER PPROFILER Profiler(typeid(*this).name(),__func__);
......
......@@ -28,9 +28,11 @@
#
############################################################################ */
#include <stdlib.h>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string.h>
#include "profiler.h"
......@@ -66,12 +68,15 @@ GetInputFileMappings(const VSTRING &input_file, const string &primary_file)
retval[primary_file] = -1;
for(string s : input_file) {
for(VSTRING::const_iterator it=input_file.begin();
it!=input_file.end();
it++) {
string s = *it;
s = Trim(s);
if( s.find(".file ") != string::npos) {
VSTRING tokens = Split(s,"\t ");
if( tokens.size() >= 3 AND tokens[0] EQ ".file" AND isdigit(tokens[1][0]) ) {
int nfile = stoi(tokens[1]);
int nfile = STOI(tokens[1]);
string file = StripQuotes(tokens[2]);
retval[file] = nfile;
}
......@@ -87,7 +92,10 @@ FindFunctionReferences(const VSTRING &input_file)
VINT retval;
int nline = 0;
for(string s : input_file) {
for(VSTRING::const_iterator it=input_file.begin();
it!=input_file.end();
it++) {
string s = *it;
if( s.find(".globl") != string::npos) {
VSTRING tokens = Split(s,"\t ");
if( tokens[1] EQ ".globl" ) {
......@@ -226,11 +234,11 @@ main(int argc, char **argv)
VSTRING tokens = Split(input_file[ii]," \t");
if( tokens.size() > 1 AND tokens[1] EQ ".loc" ) {
// We need to replace the old file number with the new one
int old_num = stoi(tokens[2]);
int old_num = STOI(tokens[2]);
int new_num = replacements[old_num];
if( new_num != 0 ) {
// Build the replacement line:
int new_line = stoi(tokens[3])-1;
int new_line = STOI(tokens[3])-1;
ss << "\t.loc";
ss << " " << new_num ;
......@@ -258,7 +266,7 @@ main(int argc, char **argv)
}
if( tokens[0] EQ ".loc" ) {
// We need to replace the old file number with the new one
int oldnum = stoi(tokens[1]);
int oldnum = STOI(tokens[1]);
int newnum = replacements[oldnum];
if( newnum != 0 ) {
// Rebuild the .loc line
......
......@@ -28,6 +28,7 @@
#
############################################################################ */
#include <stdlib.h>
#include "utils.h"
#include "profiler.h"
......@@ -111,4 +112,10 @@ Replace(const string &s,const char was, const char is)
retval += ch;
}
return retval;
}
\ No newline at end of file
}
int
STOI(const string &s)
{
return atoi(s.c_str());
}
......@@ -33,9 +33,7 @@
#include <string>
#include <vector>
typedef char *PCHAR;
typedef char const *CPCHAR;
#if __GNUC__ >= 7
typedef int8_t BYTE;
typedef uint8_t UBYTE;
......@@ -47,6 +45,21 @@ typedef uint32_t ULONG;
typedef int64_t LONGLONG;
typedef uint64_t ULONGLONG;
#else
typedef signed char BYTE;
typedef unsigned char UBYTE;
typedef signed short SHORT;
typedef unsigned short USHORT;
typedef signed int LONG;
typedef unsigned int ULONG;
typedef signed long long LONGLONG;
typedef unsigned long long ULONGLONG;
#endif
typedef std::vector<std::string> VSTRING ;
......@@ -54,3 +67,4 @@ std::string Trim(const std::string &s);
std::string StripQuotes(const std::string &s);
VSTRING Split(const std::string &s,const std::string &delimiters);
std::string Replace(const std::string &s,const char was, const char is);
int STOI(const std::string &s);
\ No newline at end of file
......@@ -31,9 +31,10 @@
#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>
#include <map>
#include <sstream>
#include <iomanip>
#include <string.h>
#include "csv.h"
#include "params.h"
#include "input_scan.h"
......@@ -54,7 +55,7 @@ scan_test(const string &filename)
{
PROFILER;
ifstream ifs;
ifs.open(filename,ifstream::in);
ifs.open(filename.c_str(),ifstream::in);
FILE *f = fopen(filename.c_str(),"r");
string input;
......@@ -85,7 +86,6 @@ scan_test(const string &filename)
fclose(f);
}
static void
CreateSymc(PARAMETERS &params,
const COB_PROGRAM_LABELS &program_labels,
......@@ -130,7 +130,7 @@ CreateSymc(PARAMETERS &params,
ss << "\"" << s << "\"" << endl;
}
ss << ";" << endl << endl;
params.symc << ss.str();
*params.symc << ss.str();
ss.str("");
bool in_copyright = true;
......@@ -201,40 +201,40 @@ CreateSymc(PARAMETERS &params,
s = ss.str();
params.symc << "asm(" << endl;
params.symc << "\".pushsection \\\".debug_gdb_scripts\\\", \\\"MS\\\",@progbits,1\\n\"" << endl;
params.symc << "\".byte 4\\n\"" << endl;
params.symc << "\".ascii \\\"gdb.inlined-script\\\\n\\\"\\n\"";
*params.symc << "asm(" << endl;
*params.symc << "\".pushsection \\\".debug_gdb_scripts\\\", \\\"MS\\\",@progbits,1\\n\"" << endl;
*params.symc << "\".byte 4\\n\"" << endl;
*params.symc << "\".ascii \\\"gdb.inlined-script\\\\n\\\"\\n\"";
int char_count = 0;
size_t i = 0;
while( i < s.size() ) {
if(char_count EQ 0) {
params.symc << "\".ascii \\\"";
*params.symc << "\".ascii \\\"";
char_count = 10 ;
}
if( char_count >= 120 ) {
params.symc << "\"" << endl << "\"";
*params.symc << "\"" << endl << "\"";
char_count = 1;
continue;
}
char ch = s[i++];
if( ch EQ '\n' ) {
params.symc << "\\\\n\\\"\\n\"" << endl;
*params.symc << "\\\\n\\\"\\n\"" << endl;
char_count = 0;
continue;
}
if( ch EQ '\\' OR ch EQ '\"' ) {
params.symc << "\\\\\\";
*params.symc << "\\\\\\";
char_count += 1;
}
params.symc << ch;
*params.symc << ch;
char_count += 1;
}
params.symc << "\".byte 0\\n\"" << endl;
params.symc << "\".popsection\\n\"" << endl;
params.symc << ");" << endl;
*params.symc << "\".byte 0\\n\"" << endl;
*params.symc << "\".popsection\\n\"" << endl;
*params.symc << ");" << endl;
}
return;
}
......@@ -273,7 +273,7 @@ main(int argc, char *argv[])
// a normalized rendition of the parsed STORAGE sections. We read that
// in, and build a COBOL identifier tree based on the various storage
// sections and the COBOL 77 01 02 03 data heirarchy.
variable_tree.ReadFromFile(params.cbl_lst);
variable_tree.ReadFromFile(*params.cbl_lst);
variable_tree.BuildCanonicalName();
#if defined(DUMPING)
//variable_tree.Dump();
......@@ -289,7 +289,7 @@ main(int argc, char *argv[])
);
// Scan the .c file for program identification and linkage information.
ScanForLinkage(params.c,
ScanForLinkage(*params.c,
params.c_filename.GetFname(),
program_labels,
cob_data,
......
......@@ -35,7 +35,7 @@
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <fstream>
#include <algorithm>
......@@ -64,7 +64,7 @@ private:
private:
std::vector<CSV_COLUMN> columns;
std::unordered_map<int,size_t> id_to_column;
std::map<int,size_t> id_to_column;
std::string
Linify(const std::string &s)
......@@ -182,7 +182,7 @@ public:
IsConsistent();
std::ofstream ofs;
ofs.open(filename,std::ofstream::out);
ofs.open(filename.c_str(),std::ofstream::out);
if(!ofs.is_open()) {
std::cerr << "Couldn't open \"" << filename << "\" for output.";
exit(1);
......
......@@ -453,7 +453,7 @@ ScanForLinkage(ifstream &ifs,
string current_entry;
string current_section;
string current_paragraph;
set<pair<string,string>>linkage_weve_seen;
set< pair<string,string> >linkage_weve_seen;
for(;;) {
getline(ifs,input);
if(ifs.eof()) {
......
......@@ -28,7 +28,10 @@
#
############################################################################ */
#include <stdlib.h>
#include <iostream>
#include <errno.h>
#include <string.h>
#ifdef _WIN32
#include "getopt.h"
......@@ -210,7 +213,7 @@ Usage()
void
OpenOrFail(std::ifstream &ifs,const std::string &fname,std::ios_base::openmode mode/* = std::ifstream::in*/)
{
ifs.open(fname,mode);
ifs.open(fname.c_str(),mode);
if(!ifs.is_open()) {
cerr << "Failed to open input file \"" << fname << "\"" << endl;
cerr << "Error: " << strerror(errno) << endl;
......@@ -221,7 +224,7 @@ OpenOrFail(std::ifstream &ifs,const std::string &fname,std::ios_base::openmode m
void
OpenOrFail(std::ofstream &ofs,const std::string &fname,std::ios_base::openmode mode/* = std::ofstream::out*/)
{
ofs.open(fname,mode);
ofs.open(fname.c_str(),mode);
if(!ofs.is_open()) {
cerr << "Failed to open output file \"" << fname << "\"" << endl;
cerr << "Error: " << strerror(errno) << endl;
......@@ -270,9 +273,9 @@ GetParameters(int argc, char *argv[])
retval.symc_filename.Decode(retval.c_filename.Stem() + ".sym.c");
//OpenOrFail(retval.cbl,retval.cbl_filename.WholePath());
OpenOrFail(retval.c,retval.c_filename.WholePath());
OpenOrFail(retval.cbl_lst,retval.cbl_lst_filename.WholePath());
OpenOrFail(retval.symc,retval.symc_filename.WholePath());
OpenOrFail(*retval.c,retval.c_filename.WholePath());
OpenOrFail(*retval.cbl_lst,retval.cbl_lst_filename.WholePath());
OpenOrFail(*retval.symc,retval.symc_filename.WholePath());
return retval;
}
......
......@@ -118,9 +118,9 @@ public:
FILENAME symc_filename; // The source file for the .debug_gdb_scrips
// //
std::ifstream cbl_lst;
std::ifstream c;
std::ofstream symc;
std::ifstream *cbl_lst;
std::ifstream *c;
std::ofstream *symc;
bool quiet;
};
......
......@@ -33,8 +33,8 @@
#if __GNUC__ >= 7
// These are static variables for the PPROFILER class
std::unordered_map<std::string,double> PPROFILER::ProfilerRoutineTimes;
std::unordered_map<std::string,LONGLONG> PPROFILER::ProfilerRoutineEntries;
std::map<std::string,double> PPROFILER::ProfilerRoutineTimes;
std::map<std::string,LONGLONG> PPROFILER::ProfilerRoutineEntries;
std::vector<double> PPROFILER::AccumulatedTimes;
std::ostream &
......
......@@ -34,7 +34,7 @@
#if __GNUC__ >= 7
#include <map>
#include <unordered_map>
#include <map>
#include <string>
#include <vector>
#include <chrono>
......@@ -48,8 +48,8 @@
class PPROFILER
{
private:
static std::unordered_map<std::string,double> ProfilerRoutineTimes;
static std::unordered_map<std::string,LONGLONG> ProfilerRoutineEntries;
static std::map<std::string,double> ProfilerRoutineTimes;
static std::map<std::string,LONGLONG> ProfilerRoutineEntries;
static std::vector<double> AccumulatedTimes;
std::string routine;
std::chrono::steady_clock::time_point time_in;
......@@ -145,7 +145,7 @@ public:
size_t max_width = 0;
std::map<std::string,double> smap;
for(std::unordered_map<std::string,double>::const_iterator it=ProfilerRoutineTimes.begin(); it!=ProfilerRoutineTimes.end(); it++) {
for(std::map<std::string,double>::const_iterator it=ProfilerRoutineTimes.begin(); it!=ProfilerRoutineTimes.end(); it++) {
max_width = std::max(max_width,it->first.length());
smap[it->first] = it->second;
}
......
......@@ -28,6 +28,7 @@
#
############################################################################ */
#include <stdlib.h>
#include <sstream>
#include "utils.h"
#include "profiler.h"
......
......@@ -4,4 +4,4 @@
// On the Unix side, there is scripting trickery to propogate this version
// code into cobcd.py and the names of packages when they are created.
#define VERSION "2.9"
#define VERSION "3.1"
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