Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 14 additions & 16 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env/python
#!/usr/bin/python3

import os
import platform

from setuptools import setup
from setuptools.extension import Extension

Expand All @@ -11,19 +10,18 @@
extra_compile_args = []
extra_link_args = []

if platform.system() == "Linux":
extra_compile_args = ["-std=c++14"]
extra_link_args = ["-lstdc++fs"]
if platform.system() == "Linux" or platform.system() == "Darwin":
extra_compile_args = ["-std=c++11"]

setup(name="ccscript",
version="1.338",
description="ccscript",
url="http://starmen.net/pkhack/ccscript",
ext_modules=[
Extension("ccscript",
source_files,
language="c++",
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args
)
])
version="1.339",
description="ccscript",
url="http://starmen.net/pkhack/ccscript",
ext_modules=[
Extension("ccscript",
source_files,
language="c++",
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args
)
])
9 changes: 4 additions & 5 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#
# Crappy makefile for ccscript compiler (ccc)
#
CXXFLAGS = -c -Wall -O3 -std=c++14
CXXFLAGS = -c -Wall -O3 -std=c++11
OBJDIR = obj
BINDIR = bin
OUTFILE = ccc
SOURCES = ccc.cpp compiler.cpp module.cpp bytechunk.cpp lexer.cpp parser.cpp ast.cpp \
stringparser.cpp symboltable.cpp table.cpp value.cpp anchor.cpp
LIBS = -lstdc++fs
OBJECTS = $(SOURCES:%.cpp=$(OBJDIR)/%.o)
INSTALL_DIR = /usr/local

Expand Down Expand Up @@ -39,13 +38,13 @@ endif
#
# Targets
#

all: ccc tests runtests


# Builds the compiler
ccc: mkdirs libsdir $(OBJECTS)
$(CXX) $(OBJECTS) $(LIBS) -o $(BINDIR)/$@
$(CXX) $(OBJECTS) -o $(BINDIR)/$@


# Ensure that bin and obj directories exist
Expand Down Expand Up @@ -111,5 +110,5 @@ $(OBJDIR)/table.o: table.h
clean:
-$(RM) $(OBJDIR)$(SEP)*.o $(BINDIR)$(SEP)$(OUTFILE)
-$(MAKE) -C tests clean


12 changes: 6 additions & 6 deletions src/bytechunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void ByteChunk::Truncate(unsigned int newsize)
bytes.resize(newsize);

pos = bytes.size();

cinfo.resize(newsize);
}

Expand Down Expand Up @@ -253,7 +253,7 @@ void ByteChunk::TranslateReferences(ByteChunk& destination,
}
}


for(vector<Reference>::const_iterator it = needed_refs.begin();
it != needed_refs.end(); ++it)
{
Expand Down Expand Up @@ -307,7 +307,7 @@ void ByteChunk::TranslateReferences(ByteChunk& destination,
// how many total bytes of the reference are left?
r.length = std::min(r.length, r.length - r.offset - overflow);
}

// Add the reference
destination.AddReference(r.location + start - offset, r.offset, r.length, r.target);
}
Expand Down Expand Up @@ -442,7 +442,7 @@ unsigned char ByteChunk::ReadByte(unsigned int pos) const
try {
return bytes.at(pos);
}
catch(std::exception e) {}
catch(std::exception&) {}
return 0;
}

Expand All @@ -453,7 +453,7 @@ unsigned short ByteChunk::ReadShort(unsigned int pos) const
result += bytes.at(pos);
result += bytes.at(pos+1) << 8;
}
catch(std::exception e) {
catch(std::exception&) {
// just give incomplete results on exception
}
return result;
Expand All @@ -468,7 +468,7 @@ unsigned int ByteChunk::ReadLong(unsigned int pos) const
result += bytes.at(pos+2) << 16;
result += bytes.at(pos+3) << 24;
}
catch(std::exception e) {
catch(std::exception&) {
}
return result;
}
Expand Down
66 changes: 43 additions & 23 deletions src/ccc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@
#include <sstream>
#include <signal.h>

#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
#ifdef _WIN32
#include <codecvt>
#include <iterator>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
#else
#include "filesystem/filesystem_mini.h"
namespace fs = filesystem;
#endif

#include "ccc.h"
#include "compiler.h"
#include "module.h"
#include "util.h"

using std::vector;
using std::string;
using std::stringstream;
using std::cout;
using std::endl;



string getbasepath(const char* p)
{
string path = p;
Expand All @@ -32,7 +39,7 @@ string getbasepath(const char* p)

void printversion()
{
cout << "ccc version 1.337 Duck Tape Edition" << endl;
cout << "ccc version 1.339 Duck Tape Edition" << endl;
}

void printusage()
Expand All @@ -48,8 +55,6 @@ void printusage()
<< " --nostdlibs Do not include the default standard libraries" << endl
<< " --summary <file> Writes a compilation summary to <file>" << endl
<< " Useful if you want to know where stuff went." << endl
//<< " --shortpause <n> Short pauses '/' are <n> frames long (default 5)" << endl
//<< " --longpause <n> Long pauses '|' are <n> frames long (default 15)" << endl
<< " --printAST Prints the abstract syntax tree for each module" << endl
<< " --printRT Prints the root symbol table for each module" << endl
<< " --printJumps Prints the compiled addresses of all labels" << endl
Expand All @@ -64,9 +69,8 @@ void printusage()
<< " put the resulting compiled text at $F20000 in the ROM Earthbound.smc" << endl;
}

int main(int argc, char* argv[])
int cccmain(int argc, const char* argv[])
{

//
// Get the default libs path
//
Expand All @@ -89,8 +93,6 @@ int main(int argc, char* argv[])
vector<string> libs;
bool noreset = false;
bool nostdlibs = false;
unsigned char shortpause;
unsigned char longpause;
bool printAST = false;
bool printRT = false;
bool printJumps = false;
Expand All @@ -105,8 +107,6 @@ int main(int argc, char* argv[])
// --libs <dir> look in <dir> for standard libraries
// -h,--help print help message
// --nostdlibs do not include default libraries
// --shortpause <n> duration of short pauses ('/')
// --longpause <n> duration of long pauses ('|')
// --printAST print AST for each module
// --printRT print root table for each module
// --printJumps print a list of jumps and addresses
Expand Down Expand Up @@ -183,14 +183,6 @@ int main(int argc, char* argv[])
}
summaryfile = argv[p++];
}
else if(!strcmp(argv[p],"--shortpause")) {
p++;
shortpause = (unsigned char)strtoul(argv[p++], NULL, 10);
}
else if(!strcmp(argv[p],"--longpause")) {
p++;
longpause = (unsigned char)strtoul(argv[p++], NULL, 10);
}
else if(!strcmp(argv[p],"--printAST")) {
p++;
printAST = true;
Expand Down Expand Up @@ -269,7 +261,7 @@ int main(int argc, char* argv[])
if(!summaryfile.empty())
{
std::fstream file;
file.open(summaryfile.c_str(), std::ios_base::out|std::ios_base::trunc);
file.open(ConvertToNativeString(summaryfile).c_str(), std::ios_base::out|std::ios_base::trunc);
if(file.fail())
{
std::cerr << "Couldn't open " << summaryfile << " to write summary file." << std::endl;
Expand All @@ -279,4 +271,32 @@ int main(int argc, char* argv[])
}

return compiler.Failed();
}
}

#ifdef _WIN32
int wmain(int argc, const wchar_t* argv[])
{
std::vector<std::string> utf8Args;
std::vector<const char*> utf8Argv;
utf8Args.reserve(argc);
utf8Args.reserve(argc);

{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;

// Convert the utf-16 args to utf-8...
// and expose the std::strings as a vector of const char*s
for(int i = 0; i < argc; ++i) {
utf8Args.emplace_back(converter.to_bytes(argv[i]));
utf8Argv.emplace_back(utf8Args[i].c_str());
}
}

return cccmain(argc, utf8Argv.data());
}
#else
int main(int argc, const char* argv[])
{
return cccmain(argc, argv);
}
#endif
3 changes: 2 additions & 1 deletion src/ccc.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
int main(int argc, char* argv[]);
extern "C" int cccmain(int argc, const char* argv[]);
extern "C" int main(int argc, const char* argv[]);
32 changes: 19 additions & 13 deletions src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
#include <iomanip>
#include <sstream>

#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
#ifdef _WIN32
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
#else
#include "filesystem/filesystem_mini.h"
namespace fs = filesystem;
#endif

#include "module.h"

Expand All @@ -20,6 +25,7 @@ namespace fs = std::experimental::filesystem::v1;
#include "module.h"
#include "symboltable.h"
#include "exception.h"
#include "util.h"

using namespace std;

Expand Down Expand Up @@ -60,7 +66,7 @@ Compiler::Compiler(const string& romfile, unsigned int adr, unsigned int endadr)
nostdlibs = false;

// Open the file
ifstream file(filename.c_str(), ifstream::binary);
ifstream file(ConvertToNativeString(filename), ifstream::binary);

if(file.fail()) {
Error("failed to open file " + filename + " for reading.");
Expand All @@ -84,7 +90,7 @@ Compiler::Compiler(const string& romfile, unsigned int adr, unsigned int endadr)
file.seekg(0, ifstream::end);
filesize = file.tellg();
file.seekg(0);
filebuffer = new char[filesize];
filebuffer = new char[(unsigned int) filesize];
file.read(filebuffer, filesize);
file.close();

Expand Down Expand Up @@ -130,7 +136,7 @@ Compiler::~Compiler()
void Compiler::WriteOutput()
{
if(failed) return;
ofstream file(filename.c_str(), ofstream::binary);
ofstream file(ConvertToNativeString(filename), ofstream::binary);

if(file.fail()) {
Error("failed to open file " + filename + " for writing.");
Expand Down Expand Up @@ -165,7 +171,7 @@ Module* Compiler::LoadModule(const std::string &filename)
// instead of SetLibTable, we should use m->Include(othermodule).
//m->SetLibTable(libtable);
string name = m->GetName();

if(GetModule(name) != NULL) {
Error("attempt to redefine module " + name + "; module names must be unique");
return NULL;
Expand All @@ -192,7 +198,7 @@ string Compiler::FindModule(const string& name, const string& filedir)
{
// Complete paths aren't looked for in include directories
if (fs::path(name).is_absolute())
return fs::exists( name )? name : "";
return fs::exists( name ) ? name : "";

// First, try in the provided file directory.
fs::path base(filedir);
Expand Down Expand Up @@ -414,8 +420,8 @@ void Compiler::AssignModuleAddresses()
bool found = false;
for(i = sorted.begin(); i != sorted.end(); ++i)
{
unsigned int size = (*i)->GetCodeSize();
if((base & 0xFFFF) + size <= 0x10000)
unsigned int size = (*i)->GetCodeSize();
if((base & 0xFFFF) + size <= 0x10000)
{
// Check for overwriting maximum address
if((endadr > 0) && (base + size >= endadr))
Expand Down Expand Up @@ -471,7 +477,7 @@ void Compiler::OutputModules()
throw Exception(ss.str());
}

m->WriteCode(filebuffer, MapVirtualAddress(m->GetBaseAddress()), filesize);
m->WriteCode(filebuffer, MapVirtualAddress(m->GetBaseAddress()), (int) filesize);

if(printJumps && m->GetName().substr(0,3) != "std")
m->PrintJumps();
Expand Down Expand Up @@ -554,7 +560,7 @@ void Compiler::DoDelayedWrites()
<< romwrites[i]->GetVirtualAddress();
throw Exception(ss.str());
}
romwrites[i]->DoWrite(filebuffer, padr, filesize);
romwrites[i]->DoWrite(filebuffer, padr, (int) filesize);
}
}

Expand All @@ -576,7 +582,7 @@ void Compiler::DoDelayedWrites()
*/
void Compiler::WriteResetInfo(const std::string &filename)
{
ofstream file(filename.c_str());
ofstream file(ConvertToNativeString(filename));

if(file.fail())
throw Exception("couldn't create info file '" + filename + "'");
Expand Down Expand Up @@ -621,7 +627,7 @@ void Compiler::WriteResetInfo(const std::string &filename)

void Compiler::ApplyResetInfo(const std::string& filename)
{
ifstream file(filename.c_str());
ifstream file(ConvertToNativeString(filename));

if(file.fail())
return;
Expand Down
Loading