Esempio n. 1
0
helpstring = \
'''usage: tpypp inputfile [outputfile]
tiny python preprocessor
(c) 2012 Isaac Evans

flags: --v for verbose mode
if output filename is not specified, it is input filename + '.p'

example macros:
#define TEMP r6
#define SWAP(A, B) mov TEMP, A\\n mov B, A\\n mov TEMP, B\\n
#include "../tests.asm"
#ifdef TEMP
SWAP(TEMP, r2)
.#else
SWAP(r5, r2)
#endif'''

pass_verbose = False

if not 2 <= len(sys.argv) <= 4:
    print helpstring
    sys.exit(-1)
if len(sys.argv) == 3 and sys.argv[1] == sys.argv[2]:
    print 'input file cannot be same as output file'
    sys.exit(-1)
if (len(sys.argv) == 3 and sys.argv[2] == '--v') or (len(sys.argv) == 4 and sys.argv[3] == '--v'):
    pass_verbose = True

preprocessor.preprocessFile(sys.argv[1], None if len(sys.argv) != 3 else sys.argv[2], pass_verbose)
Esempio n. 2
0
import filecmp
import preprocessor

def checkFile(A, B):
    return filecmp.cmp(A, B)

subdirectory = './tests/'
outputSuffix = '.p'
expectedSuffix = '.expect'

for p in [x for x in os.listdir(subdirectory) if x.endswith('.p')]:
    os.remove(subdirectory + p)
    
files = [x for x in os.listdir(subdirectory) if not x.endswith(expectedSuffix)]
if len(files) == 0:
    print('no tests found')
    
for i, filename in enumerate(files):
    pair = (subdirectory + filename, subdirectory + filename + outputSuffix)
    preprocessor.preprocessFile(*pair)
    checkPair = (subdirectory + filename + outputSuffix, subdirectory + filename + expectedSuffix)
    if checkFile(*checkPair) != True:
        print(('check failed for ' + str(checkPair)))
        sys.exit(-1)
    print(('checked ' + str(i + 1) + ' of ' + str(len(files)) + ': ' + str(pair[0])))

print('all checks ok')

for p in [x for x in os.listdir(subdirectory) if x.endswith('.p')]:
    os.remove(subdirectory + p)