Showing
7 changed files
with
32 additions
and
5 deletions
1 | +# cparse.py: modified by Franck Pommereau (2018) | ||
2 | + | ||
1 | # --------------------------------------------------------------- | 3 | # --------------------------------------------------------------- |
2 | # cparse.py | 4 | # cparse.py |
3 | # | 5 | # |
... | @@ -755,7 +757,16 @@ def p_empty(t): | ... | @@ -755,7 +757,16 @@ def p_empty(t): |
755 | pass | 757 | pass |
756 | 758 | ||
757 | def p_error(t): | 759 | def p_error(t): |
758 | - print("[%s:%s] syntax error" % (t.lineno, t.lexpos)) | 760 | + print("[%s] syntax error:" % t.lineno) |
761 | + start = t.lexer.lexdata.rfind("\n", 0, t.lexpos) | ||
762 | + if start == -1 : | ||
763 | + start = 0 | ||
764 | + else : | ||
765 | + start += 1 | ||
766 | + stop = t.lexer.lexdata.find("\n", t.lexpos) | ||
767 | + head = " " * len("[%s" % t.lineno) | ||
768 | + print(" >" + head + t.lexer.lexdata[start:stop]) | ||
769 | + print(" >" + head + (" " * (t.lexpos - start)) + "^") | ||
759 | raise ParseError() | 770 | raise ParseError() |
760 | 771 | ||
761 | yacc.yacc(debug=1) | 772 | yacc.yacc(debug=1) | ... | ... |
cctlib/cttc.py
0 → 100644
This diff is collapsed. Click to expand it.
1 | +# cx86.py: modified by Franck Pommereau (2018) | ||
2 | + | ||
1 | # --------------------------------------------------------------- | 3 | # --------------------------------------------------------------- |
2 | # cx86.py | 4 | # cx86.py |
3 | # | 5 | # |
... | @@ -177,7 +179,7 @@ class x86Registers: | ... | @@ -177,7 +179,7 @@ class x86Registers: |
177 | """Emits code that pops the callee-save registers used by | 179 | """Emits code that pops the callee-save registers used by |
178 | the stack machine off the process' stack.""" | 180 | the stack machine off the process' stack.""" |
179 | 181 | ||
180 | - for reg in self.callee_save_regs_used: | 182 | + for reg in reversed(self.callee_save_regs_used): |
181 | self.o(" popl %s" % reg, | 183 | self.o(" popl %s" % reg, |
182 | "Restore callee-save register") | 184 | "Restore callee-save register") |
183 | 185 | ... | ... |
1 | import argparse, sys, os.path | 1 | import argparse, sys, os.path |
2 | 2 | ||
3 | import ply.yacc as yacc | 3 | import ply.yacc as yacc |
4 | -from . import cparse, cvisitors, cx86 | 4 | +from . import cparse, cvisitors, cx86, cttc |
5 | -cttc = cx86 | ||
6 | 5 | ||
7 | ARCH = {"x86" : cx86, | 6 | ARCH = {"x86" : cx86, |
8 | "ttc" : cttc} | 7 | "ttc" : cttc} |
... | @@ -95,7 +94,7 @@ def main (args=None) : | ... | @@ -95,7 +94,7 @@ def main (args=None) : |
95 | ast_file = open(ast_path, "w") | 94 | ast_file = open(ast_path, "w") |
96 | else : | 95 | else : |
97 | ast_file = None | 96 | ast_file = None |
98 | - code = "\n".join(open(src).readlines()) | 97 | + code = "\n".join(l.rstrip() for l in open(src).readlines()) |
99 | ret = Compiler(ARCH[args.arch], src).compile(code, ast_file) | 98 | ret = Compiler(ARCH[args.arch], src).compile(code, ast_file) |
100 | if ast_file is not None : | 99 | if ast_file is not None : |
101 | ast_file.close() | 100 | ast_file.close() | ... | ... |
-
Please register or login to post a comment