mirror of
https://github.com/autc04/Retro68.git
synced 2024-06-09 11:29:38 +00:00
asm postprocessing filter
This commit is contained in:
parent
d8544deec7
commit
e0f694a069
9
ASFilter/CMakeLists.txt
Normal file
9
ASFilter/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "--std=c++0x")
|
||||||
|
find_package(Boost COMPONENTS regex)
|
||||||
|
|
||||||
|
add_executable(asfilter asfilter.cc)
|
||||||
|
target_link_libraries(asfilter ${Boost_LIBRARIES})
|
||||||
|
|
||||||
|
install(TARGETS asfilter RUNTIME DESTINATION bin)
|
103
ASFilter/asfilter.cc
Normal file
103
ASFilter/asfilter.cc
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
std::vector<std::string> argv2;
|
||||||
|
std::vector<const char*> argv3;
|
||||||
|
|
||||||
|
std::copy(argv, argv+argc, std::back_inserter(argv2));
|
||||||
|
argv2[0] += ".real";
|
||||||
|
|
||||||
|
std::string inputFileName;
|
||||||
|
std::string tempFileName;
|
||||||
|
|
||||||
|
char tempFileTemplate[] = "/tmp/filteredXXXXXX.s";
|
||||||
|
int fd = mkstemps(tempFileTemplate, 2);
|
||||||
|
tempFileName = tempFileTemplate;
|
||||||
|
|
||||||
|
for(auto& p : argv2)
|
||||||
|
{
|
||||||
|
if(p.substr(p.length()-2) == ".s")
|
||||||
|
{
|
||||||
|
inputFileName = p;
|
||||||
|
p = tempFileName;
|
||||||
|
std::cerr << "Temp file: " << tempFileName << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ifstream in(inputFileName);
|
||||||
|
std::ofstream out(tempFileName);
|
||||||
|
|
||||||
|
std::string wordS = "[0-9a-f][0-9a-f][0-9a-f][0-9a-f]";
|
||||||
|
boost::regex jsr("\tjsr __magic_inline_(" + wordS + "(_" + wordS + ")*)");
|
||||||
|
boost::regex word(wordS);
|
||||||
|
//boost::regex size("\t\\.size\t([a-zA-Z0-9_]+), \\.-([a-zA-Z0-9_]+)");
|
||||||
|
boost::regex globl("\t\\.globl\t([a-zA-Z0-9_]+)");
|
||||||
|
boost::regex rts("\trts");
|
||||||
|
|
||||||
|
std::string function_name = "__unknown";
|
||||||
|
while(in)
|
||||||
|
{
|
||||||
|
std::string line;
|
||||||
|
std::getline(in, line);
|
||||||
|
if(!in)
|
||||||
|
break;
|
||||||
|
|
||||||
|
boost::smatch match;
|
||||||
|
if(boost::regex_match(line, match, jsr))
|
||||||
|
{
|
||||||
|
const boost::sregex_token_iterator end;
|
||||||
|
for (boost::sregex_token_iterator p(line.cbegin(), line.cend(), word);
|
||||||
|
p != end;
|
||||||
|
++p)
|
||||||
|
{
|
||||||
|
out << "\tdc.w 0x" << *p << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*else if(boost::regex_match(line, match, size) && match[1] == match[2])
|
||||||
|
{
|
||||||
|
out << "\tdc.b 0x8e\n";
|
||||||
|
out << "\t.string \"" << match[1] << "\"\n";
|
||||||
|
out << "\t.align 2\n";
|
||||||
|
out << line << std::endl;
|
||||||
|
}*/
|
||||||
|
else if(boost::regex_match(line, match, globl))
|
||||||
|
{
|
||||||
|
out << line << std::endl;
|
||||||
|
function_name = match[1];
|
||||||
|
}
|
||||||
|
/*else if(boost::regex_match(line, rts))
|
||||||
|
{
|
||||||
|
out << line << std::endl;
|
||||||
|
out << "\tdc.b 0x8e\n";
|
||||||
|
out << "\t.string \"" << function_name << "\"\n";
|
||||||
|
out << "\tdc.b 0x00\n";
|
||||||
|
out << "\tdc.b 0x00\n";
|
||||||
|
out << "\t.align 2\n";
|
||||||
|
}*/
|
||||||
|
else
|
||||||
|
out << line << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
std::transform(argv2.begin(), argv2.end(), std::back_inserter(argv3), std::bind(&std::string::c_str, _1));
|
||||||
|
argv3.push_back(NULL);
|
||||||
|
|
||||||
|
execvp(argv3[0], const_cast<char*const*>( argv3.data() ));
|
||||||
|
perror("execvp");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
|
@ -7,4 +7,5 @@ add_subdirectory(App2)
|
||||||
add_subdirectory(Raytracer)
|
add_subdirectory(Raytracer)
|
||||||
else()
|
else()
|
||||||
add_subdirectory(MakeAPPL)
|
add_subdirectory(MakeAPPL)
|
||||||
|
add_subdirectory(ASFilter)
|
||||||
endif()
|
endif()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user