diff --git a/samples/C++/16F88.h b/samples/C++/16F88.h new file mode 100644 index 00000000..28f51ce4 --- /dev/null +++ b/samples/C++/16F88.h @@ -0,0 +1,86 @@ +/* + * This file is part of PIC + * Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net) + * + * PIC is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PIC 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +enum PIC16F88Instruction +{ + ADDWF, + ANDWF, + CLRF, + CLRW, + COMF, + DECF, + DECFSZ, + INCF, + INCFSZ, + IORWF, + MOVF, + MOVWF, + NOP, + RLF, + RRF, + SUBWF, + SWAPF, + XORWF, + BCF, + BSF, + BTFSC, + BTFSS, + ADDLW, + ANDLW, + CALL, + CLRWDT, + GOTO, + IORLW, + MOVLW, + RETFIE, + RETLW, + RETURN, + SLEEP, + SUBLW, + XORLW +}; + +class PIC16F88 +{ +public: + PIC16F88(ROM *ProgramMemory); + void Step(); + +private: + uint8_t q; + bool nextIsNop, trapped; + Memory *memory; + ROM *program; + Stack *CallStack; + Register *PC; + Register<> *WREG, *PCL, *STATUS, *PCLATCH; + PIC16F88Instruction inst; + uint16_t instrWord; + +private: + void DecodeInstruction(); + void ProcessInstruction(); + + uint8_t GetBank(); + uint8_t GetMemoryContents(uint8_t partialAddress); + void SetMemoryContents(uint8_t partialAddress, uint8_t newVal); + void CheckZero(uint8_t value); + void StoreValue(uint8_t value, bool updateZero); + uint8_t SetCarry(bool val); + uint16_t GetPCHFinalBits(); +}; diff --git a/samples/C++/Memory16F88.h b/samples/C++/Memory16F88.h new file mode 100644 index 00000000..ced2ef13 --- /dev/null +++ b/samples/C++/Memory16F88.h @@ -0,0 +1,32 @@ +/* + * This file is part of PIC + * Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net) + * + * PIC is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PIC 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include "Memory.h" + +class Memory16F88 : public Memory +{ +private: + uint8_t memory[512]; + std::map memoryMap; + +public: + Memory16F88(); + uint8_t Dereference(uint8_t bank, uint8_t partialAddress); + uint8_t *Reference(uint8_t bank, uint8_t partialAddress); + uint8_t *operator [](uint32_t ref); +}; diff --git a/samples/C++/ThreadedQueue.h b/samples/C++/ThreadedQueue.h new file mode 100644 index 00000000..6b2fbaad --- /dev/null +++ b/samples/C++/ThreadedQueue.h @@ -0,0 +1,76 @@ +/* + * This file is part of IRCBot + * Copyright © 2014 Rachel Mant (dx-mon@users.sourceforge.net) + * + * IRCBot 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 3 of the License, or + * (at your option) any later version. + * + * IRCBot 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, see . + */ + +#ifndef __THREADED_QUEUE_H__ +#define __THREADED_QUEUE_H__ + +#include +#include + +template +class ThreadedQueue : public std::queue +{ +private: + pthread_mutex_t queueMutex; + pthread_cond_t queueCond; + +public: + ThreadedQueue() + { + pthread_mutexattr_t mutexAttrs; + pthread_condattr_t condAttrs; + + pthread_mutexattr_init(&mutexAttrs); + pthread_mutexattr_settype(&mutexAttrs, PTHREAD_MUTEX_ERRORCHECK); + pthread_mutex_init(&queueMutex, &mutexAttrs); + pthread_mutexattr_destroy(&mutexAttrs); + + pthread_condattr_init(&condAttrs); + pthread_condattr_setpshared(&condAttrs, PTHREAD_PROCESS_PRIVATE); + pthread_cond_init(&queueCond, &condAttrs); + pthread_condattr_destroy(&condAttrs); + } + + ~ThreadedQueue() + { + pthread_cond_destroy(&queueCond); + pthread_mutex_destroy(&queueMutex); + } + + void waitItems() + { + pthread_mutex_lock(&queueMutex); + pthread_cond_wait(&queueCond, &queueMutex); + pthread_mutex_unlock(&queueMutex); + } + + void signalItems() + { + pthread_mutex_lock(&queueMutex); + pthread_cond_broadcast(&queueCond); + pthread_mutex_unlock(&queueMutex); + } + + void push(T item) + { + std::queue::push(item); + signalItems(); + } +}; + +#endif /*__THREADED_QUEUE_H__*/ diff --git a/samples/C/ArrowLeft.h b/samples/C/ArrowLeft.h new file mode 100644 index 00000000..b3577c0e --- /dev/null +++ b/samples/C/ArrowLeft.h @@ -0,0 +1,93 @@ +/* + * This file is part of GTK++ (libGTK++) + * Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net) + * + * GTK++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GTK++ 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +/* GdkPixbuf RGBA C-Source image dump */ + +#ifdef __SUNPRO_C +#pragma align 4 (ArrowLeft) +#endif +#ifdef __GNUC__ +static const uint8_t ArrowLeft[] __attribute__ ((__aligned__ (4))) = +#else +static const uint8_t ArrowLeft[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (1600) */ + "\0\0\6X" + /* pixdata_type (0x1010002) */ + "\1\1\0\2" + /* rowstride (80) */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0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0"}; + + diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 0c1a07ff..d629c302 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -32,6 +32,15 @@ class TestHeuristcs < Test::Unit::TestCase languages = ["C++", "Objective-C"] results = Heuristics.disambiguate_c(fixture("C++/render_adapter.cpp"), languages) assert_equal Language["C++"], results.first + languages = ["C++", "Objective-C", "C"] + results = Heuristics.disambiguate_c(fixture("C++/ThreadedQueue.h"), languages) + assert_equal Language["C++"], results.first + end + + def test_c_by_heuristics + languages = ["C++", "Objective-C", "C"] + results = Heuristics.disambiguate_c(fixture("C/ArrowLeft.h"), languages) + assert_equal nil, results.first end def test_detect_still_works_if_nothing_matches