Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
cct
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
0
Wiki
Network
Create a new issue
Commits
Authored by
Franck Pommereau
2018-04-20 12:36:09 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
75ec9cdd6d6c2baa933f82bcbfc3a9066605c773
75ec9cdd
1 parent
d2ca43ee
cttc.py first version, not tested yet
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
5 deletions
cctlib/clex.py
cctlib/cparse.py
cctlib/cttc.py
cctlib/cvisitors.py
cctlib/cx86.py
cctlib/main.py
samples/expr.c
cctlib/clex.py
View file @
75ec9cd
# clex.py: modified by Franck Pommereau (2018)
# ---------------------------------------------------------------
# clex.py
#
...
...
cctlib/cparse.py
View file @
75ec9cd
# cparse.py: modified by Franck Pommereau (2018)
# ---------------------------------------------------------------
# cparse.py
#
...
...
@@ -755,7 +757,16 @@ def p_empty(t):
pass
def
p_error
(
t
):
print
(
"[
%
s:
%
s] syntax error"
%
(
t
.
lineno
,
t
.
lexpos
))
print
(
"[
%
s] syntax error:"
%
t
.
lineno
)
start
=
t
.
lexer
.
lexdata
.
rfind
(
"
\n
"
,
0
,
t
.
lexpos
)
if
start
==
-
1
:
start
=
0
else
:
start
+=
1
stop
=
t
.
lexer
.
lexdata
.
find
(
"
\n
"
,
t
.
lexpos
)
head
=
" "
*
len
(
"[
%
s"
%
t
.
lineno
)
print
(
" >"
+
head
+
t
.
lexer
.
lexdata
[
start
:
stop
])
print
(
" >"
+
head
+
(
" "
*
(
t
.
lexpos
-
start
))
+
"^"
)
raise
ParseError
()
yacc
.
yacc
(
debug
=
1
)
...
...
cctlib/cttc.py
0 → 100644
View file @
75ec9cd
This diff is collapsed. Click to expand it.
cctlib/cvisitors.py
View file @
75ec9cd
# cvisitors.py: modified by Franck Pommereau (2018)
# ---------------------------------------------------------------
# cvisitors.py
#
...
...
cctlib/cx86.py
View file @
75ec9cd
# cx86.py: modified by Franck Pommereau (2018)
# ---------------------------------------------------------------
# cx86.py
#
...
...
@@ -177,7 +179,7 @@ class x86Registers:
"""Emits code that pops the callee-save registers used by
the stack machine off the process' stack."""
for
reg
in
self
.
callee_save_regs_used
:
for
reg
in
reversed
(
self
.
callee_save_regs_used
)
:
self
.
o
(
" popl
%
s"
%
reg
,
"Restore callee-save register"
)
...
...
cctlib/main.py
View file @
75ec9cd
import
argparse
,
sys
,
os.path
import
ply.yacc
as
yacc
from
.
import
cparse
,
cvisitors
,
cx86
cttc
=
cx86
from
.
import
cparse
,
cvisitors
,
cx86
,
cttc
ARCH
=
{
"x86"
:
cx86
,
"ttc"
:
cttc
}
...
...
@@ -95,7 +94,7 @@ def main (args=None) :
ast_file
=
open
(
ast_path
,
"w"
)
else
:
ast_file
=
None
code
=
"
\n
"
.
join
(
open
(
src
)
.
readlines
())
code
=
"
\n
"
.
join
(
l
.
rstrip
()
for
l
in
open
(
src
)
.
readlines
())
ret
=
Compiler
(
ARCH
[
args
.
arch
],
src
)
.
compile
(
code
,
ast_file
)
if
ast_file
is
not
None
:
ast_file
.
close
()
...
...
samples/expr.c
0 → 100644
View file @
75ec9cd
int
main
(
int
argc
,
char
**
argv
)
{
int
a
;
int
b
;
int
c
;
int
d
;
a
=
1
;
b
=
1
+
a
;
c
=
1
+
a
+
b
;
d
=
1
+
a
+
b
+
c
;
a
=
a
*
(
1
*
a
+
2
*
b
+
3
*
c
+
4
*
d
)
-
b
*
(
2
*
a
+
3
*
b
+
4
*
c
+
4
*
d
);
}
Please
register
or
login
to post a comment