Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compiler-construction
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
User expired
compiler-construction
Commits
94474365
Commit
94474365
authored
5 years ago
by
krf41037
Browse files
Options
Downloads
Patches
Plain Diff
Moved cfg dot printing to print_tac
parent
d396c0d9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
app/mc_ir.c
+2
-1
2 additions, 1 deletion
app/mc_ir.c
include/mcc/cfg.h
+0
-40
0 additions, 40 deletions
include/mcc/cfg.h
include/mcc/tac_print.h
+3
-1
3 additions, 1 deletion
include/mcc/tac_print.h
src/cfg.c
+0
-38
0 additions, 38 deletions
src/cfg.c
src/tac_print.c
+132
-1
132 additions, 1 deletion
src/tac_print.c
with
137 additions
and
81 deletions
app/mc_ir.c
+
2
−
1
View file @
94474365
...
...
@@ -111,7 +111,8 @@ int main(int argc, char *argv[]) {
}
struct
mcc_tac
*
tac
=
mcc_tac_build
(
prog
,
symbol_table
);
tac_print
(
tac
,
stdout
);
mcc_tac_print
(
tac
,
stdout
);
mcc_print_cfg_dot
(
tac
,
stdout
);
mcc_symbol_table_delete_table
(
symbol_table
);
mcc_symbol_table_delete_error_collector
(
ec
);
...
...
This diff is collapsed.
Click to expand it.
include/mcc/cfg.h
deleted
100644 → 0
+
0
−
40
View file @
d396c0d9
#ifndef _GFG_H_
#define _GFG_H_
#include
"mcc/tac_build.h"
#include
"mcc/tac.h"
#include
"mcc/symbol_table.h"
struct
mcc_cfg
{
int
block_size
;
struct
mcc_cfg_basic_block
*
basic
;
struct
mcc_cfg
*
next
;
};
struct
mcc_cfg_edge
{
struct
mcc_cfg_basic_block
*
destination
;
struct
mcc_cfg_edge
*
next
;
};
struct
mcc_cfg_basic_block
{
int
id
;
struct
mcc_tac_entry
*
start
;
struct
mcc_tac_entry
*
end
;
struct
mcc_cfg_edge
*
incoming
;
struct
mcc_cfg_edge
*
outgoing
;
struct
mcc_cfg_basic_block
*
next
;
};
struct
mcc_cfg
*
mcc_create_cfg
(
struct
mcc_tac
*
tac
);
struct
mcc_cfg_basic_block
*
mcc_create_cfg_basic_block
(
struct
mcc_tac
*
tac
);
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
include/mcc/tac_print.h
+
3
−
1
View file @
94474365
...
...
@@ -8,6 +8,8 @@
static
const
char
*
tac_type
(
enum
mcc_tac_operation
type
);
void
tac_print
(
struct
mcc_tac
*
tac
,
FILE
*
out
);
void
mcc_tac_print
(
struct
mcc_tac
*
tac
,
FILE
*
out
);
void
mcc_print_cfg_dot
(
struct
mcc_tac
*
tac
,
FILE
*
out
);
#endif
This diff is collapsed.
Click to expand it.
src/cfg.c
deleted
100644 → 0
+
0
−
38
View file @
d396c0d9
#include
"mcc/cfg.h"
#include
"mcc/tac_build.h"
#include
"mcc/tac.h"
#include
"mcc/symbol_table.h"
#include
<stdio.h>
#include
<string.h>
#include
<stdlib.h>
struct
mcc_cfg
*
mcc_create_cfg
(
struct
mcc_tac
*
tac
)
{
struct
mcc_cfg
*
graph
=
NULL
;
}
// Printing
void
mcc_cfg_to_dot
(
FILE
*
out
,
struct
mcc_cfg
*
graph
)
{
fprintf
(
out
,
"digraph
\"
Control Flow Graphs
\"
{
\n
"
);
fprintf
(
out
,
"
\t
graph [pad=
\"
0.5
\"
, nodesep=
\"
0.5
\"
, ranksep=
\"
2
\"
]
\n
"
);
fprintf
(
out
,
"
\t
node [shape=plaintext]
\n
"
);
while
(
graph
!=
NULL
)
{
mcc_cfg_visit
(
graph
->
basic
,
mcc_cfg_print_graph_visitor
,
out
);
graph
=
graph
->
next
;
}
fprintf
(
out
,
"}
\n
"
);
}
void
mcc_cfg_print_graph_visitor
(
struct
mcc_cfg_basic_block
*
block
,
void
*
args
)
{
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/tac_print.c
+
132
−
1
View file @
94474365
...
...
@@ -6,6 +6,8 @@
#include
"mcc/symbol_table_print.h"
#include
"mcc/tac.h"
#define LABEL_SIZE 64
static
const
char
*
tac_type
(
enum
mcc_tac_operation
type
)
{
switch
(
type
)
{
...
...
@@ -82,7 +84,7 @@ static const char *tac_type(enum mcc_tac_operation type)
return
"ERROR"
;
}
void
tac_print
(
struct
mcc_tac
*
tac
,
FILE
*
out
)
void
mcc_
tac_print
(
struct
mcc_tac
*
tac
,
FILE
*
out
)
{
fprintf
(
out
,
"------------------------------
\n
"
);
fprintf
(
out
,
"- TAC -
\n
"
);
...
...
@@ -243,4 +245,133 @@ void tac_print(struct mcc_tac *tac, FILE *out)
fprintf
(
out
,
"ERROR
\n
"
);
}
}
}
static
void
print_dot_begin
(
FILE
*
out
)
{
assert
(
out
);
fprintf
(
out
,
"digraph
\"
AST
\"
{
\n
"
"
\t
nodesep=0.6
\n
"
);
}
static
void
print_dot_end
(
FILE
*
out
)
{
assert
(
out
);
fprintf
(
out
,
"}
\n
"
);
}
static
void
print_dot_node
(
FILE
*
out
,
const
void
*
node
,
const
char
*
label
)
{
assert
(
out
);
assert
(
node
);
assert
(
label
);
fprintf
(
out
,
"
\t\"
%p
\"
[shape=box, label=
\"
%s
\"
];
\n
"
,
node
,
label
);
}
static
void
print_dot_edge
(
FILE
*
out
,
const
void
*
src_node
,
const
void
*
dst_node
,
const
char
*
label
)
{
assert
(
out
);
assert
(
src_node
);
assert
(
dst_node
);
assert
(
label
);
fprintf
(
out
,
"
\t\"
%p
\"
->
\"
%p
\"
[label=
\"
%s
\"
];
\n
"
,
src_node
,
dst_node
,
label
);
}
static
void
print_dot_node_diamond
(
FILE
*
out
,
const
void
*
node
,
const
char
*
label
)
{
assert
(
out
);
assert
(
node
);
assert
(
label
);
fprintf
(
out
,
"
\t\"
%p
\"
[shape=diamond, label=
\"
%s
\"
];
\n
"
,
node
,
label
);
}
static
void
print_dot_node_label
(
FILE
*
out
,
int
label
)
{
assert
(
out
);
assert
(
label
);
fprintf
(
out
,
"
\t\"
Label%d
\"
[shape=box, label=
\"
Label%d
\"
];
\n
"
,
label
,
label
);
}
static
void
print_dot_edge_from_label
(
FILE
*
out
,
const
void
*
dst_node
,
int
label
)
{
assert
(
out
);
assert
(
dst_node
);
assert
(
label
);
fprintf
(
out
,
"
\t\"
Label%d
\"
->
\"
%p
\"
[label=
\"
%s
\"
];
\n
"
,
label
,
dst_node
,
""
);
}
static
void
print_dot_edge_label
(
FILE
*
out
,
const
void
*
src_node
,
int
label
,
bool
if_else
)
{
assert
(
out
);
assert
(
src_node
);
assert
(
label
);
if
(
if_else
==
true
){
fprintf
(
out
,
"
\t\"
%p
\"
->
\"
Label%d
\"
[label=
\"
%s
\"
];
\n
"
,
src_node
,
label
,
"YES"
);
}
else
{
fprintf
(
out
,
"
\t\"
%p
\"
->
\"
Label%d
\"
[label=
\"
%s
\"
];
\n
"
,
src_node
,
label
,
""
);
}
}
void
mcc_print_cfg_dot
(
struct
mcc_tac
*
tac
,
FILE
*
out
)
{
fprintf
(
out
,
"------------------------------
\n
"
);
fprintf
(
out
,
"- CFG DOT -
\n
"
);
fprintf
(
out
,
"------------------------------
\n
"
);
for
(
int
i
=
0
;
i
<
tac
->
tac_entries
->
size
;
i
++
)
{
struct
mcc_tac_entry
*
entry
=
tac
->
tac_entries
->
arr
[
i
];
struct
mcc_tac_entry
*
next_entry
=
tac
->
tac_entries
->
arr
[
i
+
1
];
const
char
*
op_type
=
tac_type
(
entry
->
tac_op
);
switch
(
entry
->
tac_op
)
{
case
MCC_TAC_BOOL
:
case
MCC_TAC_IDENTIFIER_BOOL
:
case
MCC_TAC_BOOL_LITERAL
:
case
MCC_TAC_INT
:
case
MCC_TAC_IDENTIFIER_INT
:
case
MCC_TAC_INT_LITERAL
:
case
MCC_TAC_FLOAT
:
case
MCC_TAC_IDENTIFIER_FLOAT
:
case
MCC_TAC_FLOAT_LITERAL
:
case
MCC_TAC_STRING
:
case
MCC_TAC_IDENTIFIER_STRING
:
case
MCC_TAC_STRING_LITERAL
:
/*
* have to do this otherwise 'label can only be part of
* a statement and a declaration is not a statement' error
*/
assert
(
entry
->
result
);
char
label
[
LABEL_SIZE
]
=
{
0
};
snprintf
(
label
,
sizeof
(
label
),
"%s = %s (%s)
\n
"
,
entry
->
result
,
entry
->
arg1
,
op_type
);
print_dot_node
(
out
,
entry
,
label
);
if
(
next_entry
->
tac_op
==
MCC_TAC_LABEL
){
print_dot_edge_label
(
out
,
entry
,
next_entry
->
result
,
false
);
}
break
;
default:
fprintf
(
out
,
"error %d
\n
"
,
op_type
);
break
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment