52# include <asmjit/core.h>
53# include <asmjit/x86.h>
67# include <sys/types.h>
84# include <type_traits>
90using namespace asmjit;
99#define STDCOUT std::cout
101const int CVT_NONE = 0;
102const int CVT_ASM = 1;
103const int CVT_PASCAL = 2;
136template <
typename T1>
146 return message.c_str();
150template <
typename T1>
152 static_assert(
sizeof(T1) &&
false,
153 "T1 must be either std::string or std::wstring");
154 T1 readFile(
const T1) { }
160template <
typename T1>
163 std::basic_ifstream< T1 > ifile;
164 std::basic_ofstream< T1 > ofile;
170 ::std::basic_string < T1 > PL_ident;
171 ::std::basic_stringstream < T1 > PL_source;
173 using PosType =
typename std::conditional< std::is_same< T1, char>::value,
174 uint32_t, uint64_t >::type;
177 PosType PL_lookaheadPosition;
178 PosType PL_nestedComment;
199 PL_lookaheadPosition = PL_lookaheadPosition + 1;
200 if (PL_lookaheadPosition >= PL_size)
return 0x0;
206 PL_source.get(buffer,1);
207 PL_buffer = ((uint16_t) buffer[0] << 8) | 0x00;
210 PL_source.get(buffer,2);
211 PL_buffer = ((uint16_t) buffer[0] << 8) | buffer[1];
216 std::basic_string< T1 >
217 PL_parseFile(
const std::basic_string< T1 > &filename,
PL_Encoder &in)
219 if (std::is_same< T1, char >::value) { ifile.open(filename); }
else
220 if (std::is_same< T1, std::string>::value) { ifile.open(filename); }
222 ifile.imbue(std::locale(std::locale(),
223 new std::codecvt_utf8< wchar_t >));
224 PL_size =
sizeof(wchar_t);
227 if (ifile.is_open()) {
228 PL_source << ifile.rdbuf();
229 PL_size =
sizeof( char );
232 PL_source.seekg(0, std::ios::end);
233 PL_size = PL_source.tellg();
234 PL_source.seekg(0, std::ios::beg);
236 return PL_source.str();
246 if (!(in.PL_lookaheadChar = in.getch()))
250 (in.PL_lookaheadChar ==
' ' ) ||
251 (in.PL_lookaheadChar ==
'\t')) {
255 if (in.PL_lookaheadChar ==
'\n') {
261 if (in.PL_lookaheadChar ==
'/')
263 if (!(in.PL_lookaheadChar = in.getch())) {
268 if (in.PL_lookaheadChar ==
'*')
270 in.PL_nestedComment =
271 in.PL_nestedComment + 1;
275 if (!(in.PL_lookaheadChar = in.getch())) {
280 if (in.PL_lookaheadChar ==
'\n') {
286 if (in.PL_lookaheadChar ==
'/') {
287 if (!(in.PL_lookaheadChar = in.getch())) {
292 if (in.PL_lookaheadChar ==
'*') {
293 in.PL_nestedComment =
294 in.PL_nestedComment + 1;
299 if (in.PL_lookaheadChar ==
'*') {
300 if (!(in.PL_lookaheadChar = in.getch())) {
305 if (in.PL_lookaheadChar ==
'/') {
306 in.PL_nestedComment =
307 in.PL_nestedComment - 1;
if (
308 in.PL_nestedComment < 1)
321 if (in.PL_lookaheadChar ==
'%') {
324 if (!(in.PL_lookaheadChar = in.getch()))
327 if (in.PL_lookaheadChar ==
'\n') {
334 if (in.PL_lookaheadPosition >= in.PL_size)
340 (in.PL_lookaheadChar >=
'a' && in.PL_lookaheadChar <=
'z') ||
341 (in.PL_lookaheadChar >=
'A' && in.PL_lookaheadChar <=
'A') ||
342 (in.PL_lookaheadChar ==
'_'))
345 in.PL_ident += in.PL_lookaheadChar;
348 in.PL_lookaheadPosition !=
351 in.PL_lookaheadChar = in.getch();
352 if (in.PL_lookaheadChar ==
'\n') {
354 in.PL_ident << std::endl;
362 (in.PL_lookaheadChar >=
'a' && in.PL_lookaheadChar <=
'z') ||
363 (in.PL_lookaheadChar >=
'A' && in.PL_lookaheadChar <=
'A') ||
364 (in.PL_lookaheadChar >=
'0' && in.PL_lookaheadChar <=
'9') ||
365 (in.PL_lookaheadChar ==
'_')) {
366 if (in.PL_nestedComment < 1) {
372 in.PL_ident << std::endl;
383on_setMode(std::string mode) {
384 if (mode == std::string(
"pascal")) convert_mode = CVT_PASCAL;
else
385 if (mode == std::string(
"asm" )) convert_mode = CVT_ASM;
393using namespace prolog;
395main(
int argc,
char** argv)
406 input.PL_lookaheadPosition = -1;
408 input.PL_nestedComment = 0;
415 if (std::string(argv[1]).size() < 1) {
419 if (std::string(argv[2]).size() < 1) {
424 input.PL_parseFile( std::string( argv[1] ), input );
428 <<
"Compiled: OK" << std::endl
429 <<
"Lines : " << input.PL_lineno << std::endl;
434 <<
"error : " << input.PL_lineno
436 <<
"reason: " << e.what()
This is a helper class for the zwapel Prolog classes.
int PL_success()
Prolog member function, that return TRUE on success rule.
int PL_fail()
Prolog member function, that return FALSE on fail rule.