New tool in. New ignore for tools, so that cvs stops yapping.

This commit is contained in:
grinvader
2005-07-16 18:25:34 +00:00
parent 26e498e70e
commit db66efd2e7
5 changed files with 187 additions and 17 deletions

View File

@@ -1,11 +1,12 @@
config.log
.gdbinit
Makefile
aclocal.m4
config.h
configure
config.cache
.gdbinit
config.h
config.log
config.status
configure
parsegen
zsnesd
zsnes

View File

@@ -115,13 +115,19 @@ ${PSR}: parsegen.cpp
ALL:
rm -f version.o
tools: minwhite extraext sec-test srccount nreplace
tools: cutrtype extraext minwhite nreplace sec-test srccount
cutrtype: ${TOOLSOBJ}
@CXX@ @CFLAGS@ -o ${TOOLSDIR}/cutrtype ${TOOLSDIR}/cutrtype.cpp ${TOOLSOBJ}
extraext: ${TOOLSOBJ}
@CXX@ @CFLAGS@ -o ${TOOLSDIR}/extraext ${TOOLSDIR}/extraext.cpp ${TOOLSOBJ}
minwhite: ${TOOLSOBJ}
@CXX@ @CFLAGS@ -o ${TOOLSDIR}/minwhite ${TOOLSDIR}/minwhite.cpp ${TOOLSDIR}/fileutil.o
extraext: ${TOOLSOBJ}
@CXX@ @CFLAGS@ -o ${TOOLSDIR}/extraext ${TOOLSDIR}/extraext.cpp ${TOOLSOBJ}
nreplace: ${TOOLSOBJ}
@CXX@ @CFLAGS@ -o ${TOOLSDIR}/nreplace ${TOOLSDIR}/nreplace.cpp ${TOOLSDIR}/fileutil.o
sec-test: ${TOOLSOBJ}
@CXX@ @CFLAGS@ -o ${TOOLSDIR}/sec-test ${TOOLSDIR}/sec-test.cpp ${TOOLSOBJ}
@@ -129,9 +135,6 @@ sec-test: ${TOOLSOBJ}
srccount: ${TOOLSOBJ}
@CXX@ @CFLAGS@ -o ${TOOLSDIR}/srccount ${TOOLSDIR}/srccount.cpp ${TOOLSDIR}/fileutil.o
nreplace: ${TOOLSOBJ}
@CXX@ @CFLAGS@ -o ${TOOLSDIR}/nreplace ${TOOLSDIR}/nreplace.cpp ${TOOLSDIR}/fileutil.o
cfgload.o: cfgload.c macros.mac
cfgparse.o: cfgparse.psr
endmem.o: endmem.asm macros.mac

6
zsnes/src/tools/.cvsignore Executable file
View File

@@ -0,0 +1,6 @@
cutrtype
extraext
minwhite
nreplace
sec-test
srccount

View File

@@ -6,22 +6,24 @@ g++ -Wall -O3 -o fileutil.o -c fileutil.cpp
g++ -Wall -O3 -o strutil.o -c strutil.cpp
Minimize Whitespace:
g++ -Wall -O3 -o minwhite.exe minwhite.cpp fileutil.o
Cut Redundant ASM Typecasts:
g++ -Wall -O3 -o cutrtype.exe cutrtype.cpp fileutil.o strutil.o
Extra EXTSYMs:
g++ -Wall -O3 -o extraext.exe extraext.cpp fileutil.o strutil.o
Minimize Whitespace:
g++ -Wall -O3 -o minwhite.exe minwhite.cpp fileutil.o
Nach's Replacer:
g++ -Wall -O3 -o nreplace.exe nreplace.cpp fileutil.o
Section Tester:
g++ -Wall -O3 -o sec-test.exe sec-test.cpp fileutil.o strutil.o
Source Counter:
g++ -Wall -O3 -o srccount.exe srccount.cpp fileutil.o
Nach's Replacer:
g++ -Wall -O3 -o nreplace.exe nreplace.cpp fileutil.o
All the tools scan every compatible file they find from the directory
they are in. It also scans all sub directories recursively.

158
zsnes/src/tools/cutrtype.cpp Executable file
View File

@@ -0,0 +1,158 @@
/*
Copyright (C) 2005 Nach, grinvader ( http://www.zsnes.com )
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
This is part of a toolkit used to assist in ZSNES development
This program removes redundant typecasting in reg<->memory transfers
*/
#include <iostream>
#include <fstream>
using namespace std;
#include "fileutil.h"
#include "strutil.h"
#define LINE_LENGTH 2048
static unsigned char getsize(const string& token, const char mode)
{
unsigned char val = 0;
if (mode == 'r')
{
val = 0;
if (token == "al" || token == "ah" || token == "bl" || token == "bh" ||
token == "cl" || token == "ch" || token == "dl" || token == "dh" ||
token == "di" || token == "si" || token == "bp")
{ val = 1; }
else if (token == "ax" || token == "bx" || token == "cx" || token == "dx")
{ val = 2; }
else if (token == "eax" || token == "ebx" || token == "ecx" ||
token == "edx" || token == "edi" || token == "esi" ||
token == "ebp")
{ val = 4; }
}
if (mode == 't')
{
val = 0xFF;
if (token == "byte") { val = 1; }
if (token == "word") { val = 2; }
if (token == "dword") { val = 4; }
}
return (val);
}
static bool isredund(string& cheese, const vector<string>& wine, const char bread)
{
if (getsize(wine[bread],'t') == getsize(wine[(bread+2)%3], 'r'))
{
size_t loc = cheese.find(wine[bread]);
cheese.erase(loc, cheese.find(wine[bread+1])-loc-1);
return (true); // how are you gentlemen ?
}
return (false);
}
void handle_file(const char *filename, size_t orig_fsize)
{
bool modify_file = false;
vector<string> file_buffer;
ifstream file(filename, ios::in);
if (file)
{
char line[LINE_LENGTH];
while (file.getline(line, LINE_LENGTH))
{
vector<string> tokens;
string mline(line);
char *p = line;
while (isspace(*p)) { p++; }
if (!strncasecmp(p, "mov ", strlen("mov ")))
{
p += strlen("mov ");
while (isspace(*p)) { p++; }
Tokenize(p, tokens, ";");
string not_commented = tokens[0];
tokens.clear();
Tokenize(not_commented, tokens, ", []");
if (tokens.size()>2)
{
modify_file |= isredund(mline, tokens, 0) ||
isredund(mline, tokens, 1);
}
}
file_buffer.push_back(mline);
}
file.close();
}
else
{
cerr << "Could not open " << filename << "." << endl;
}
if (modify_file)
{
ofstream file(filename, ios::out);
if (file)
{
for (vector<string>::iterator i = file_buffer.begin(); i != file_buffer.end(); i++)
{
file.write(i->data(), i->length());
file << "\n";
}
size_t cur_fsize = file.tellp();
file.close();
cout << "Trimmed " << filename << " of " << orig_fsize-cur_fsize
<< " bytes." << endl;
}
else
{
cerr << filename
<< " has redundant typecasts, but a trimmed copy can't be saved."
<< endl;
}
}
}
void cut_redund(const char *filename, struct stat& stat_buffer)
{
if (is_asm_file(filename))
{
handle_file(filename, stat_buffer.st_size);
}
}
int main()
{
parse_dir(".", cut_redund);
return(0);
}