Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
gcc-python-plugin/test.py at master · Python-Repository-Hub/gcc-python-plugin · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
Python-Repository-Hub
/
gcc-python-plugin
Public
forked from
davidmalcolm/gcc-python-plugin
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
gcc-python-plugin
/
test.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
132 lines (113 loc) · 4.57 KB
master
Breadcrumbs
gcc-python-plugin
/
test.py
Copy path
Top
File metadata and controls
Code
Blame
132 lines (113 loc) · 4.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Copyright 2011 David Malcolm <dmalcolm@redhat.com>
# Copyright 2011 Red Hat, Inc.
#
# This 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.
#
# This program 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
# <http://www.gnu.org/licenses/>.
# Sample python script, to be run by our gcc plugin (see "make test")
#print "hello world"
import
gcc
import
sys
print
(
'sys.version: %s'
%
sys
.
version
)
#print 'sys.path:', sys.path
#help(gcc)
print
(
help
(
gcc
.
AddrExpr
))
print
(
gcc
.
Type
)
print
(
gcc
.
Type
.
char
)
print
(
help
(
gcc
.
Type
))
from
gccutils
import
get_src_for_loc
,
cfg_to_dot
,
invoke_dot
def
my_pass_execution_callback
(
*
args
,
**
kwargs
):
print
(
'my_pass_execution_callback was called: args=%r kwargs=%r'
%
(
args
,
kwargs
))
print
(
'gcc.get_translation_units(): %s'
%
gcc
.
get_translation_units
())
for
u
in
gcc
.
get_translation_units
():
print
(
'u: %s %r'
%
(
u
,
u
))
u
.
debug
()
print
(
'u.block: %s'
%
u
.
block
)
#help(args[0])
(
optpass
,
fun
)
=
args
print
(
'optpass: %r'
%
optpass
)
print
(
'dir(optpass): %r'
%
dir
(
optpass
))
print
(
'optpass.name: %r'
%
optpass
.
name
)
print
(
'fun: %r'
%
fun
)
if
fun
:
print
(
'fun.cfg: %r'
%
fun
.
cfg
)
if
fun
.
cfg
:
#print help(fun.cfg)
print
(
'fun.cfg.basic_blocks: %r'
%
fun
.
cfg
.
basic_blocks
)
print
(
'fun.cfg.entry: %r'
%
fun
.
cfg
.
entry
)
print
(
'fun.cfg.exit: %r'
%
fun
.
cfg
.
exit
)
print
(
'fun.cfg.entry.succs: %r'
%
fun
.
cfg
.
entry
.
succs
)
print
(
'fun.cfg.exit.preds: %r'
%
fun
.
cfg
.
exit
.
preds
)
dot
=
cfg_to_dot
(
fun
.
cfg
)
print
(
dot
)
invoke_dot
(
dot
)
for
bb
in
fun
.
cfg
.
basic_blocks
:
print
(
'bb: %r'
%
bb
)
print
(
'bb.gimple: %r'
%
bb
.
gimple
)
if
isinstance
(
bb
.
gimple
,
list
):
for
stmt
in
bb
.
gimple
:
print
(
' %r: %r : %s column: %i block: %r'
%
(
stmt
,
repr
(
str
(
stmt
)),
stmt
.
loc
,
stmt
.
loc
.
column
,
stmt
.
block
))
print
(
get_src_for_loc
(
stmt
.
loc
))
print
(
' '
*
(
stmt
.
loc
.
column
-
1
)
+
'^'
)
if
hasattr
(
stmt
,
'loc'
):
print
(
' stmt.loc: %r'
%
stmt
.
loc
)
if
hasattr
(
stmt
,
'lhs'
):
print
(
' stmt.lhs: %r'
%
stmt
.
lhs
)
if
hasattr
(
stmt
,
'exprtype'
):
print
(
' stmt.exprtype: %r'
%
stmt
.
exprtype
)
if
hasattr
(
stmt
,
'exprcode'
):
print
(
' stmt.exprcode: %r'
%
stmt
.
exprcode
)
if
hasattr
(
stmt
,
'fn'
):
print
(
' stmt.fn: %r %s'
%
(
stmt
.
fn
,
stmt
.
fn
))
if
hasattr
(
stmt
,
'retval'
):
print
(
' stmt.retval: %r'
%
stmt
.
retval
)
if
hasattr
(
stmt
,
'rhs'
):
print
(
' stmt.rhs: %r'
%
stmt
.
rhs
)
def
my_pre_genericize_callback
(
*
args
,
**
kwargs
):
print
(
'my_pre_genericize_callback was called: args=%r kwargs=%r'
%
(
args
,
kwargs
))
#help(args[0])
t
=
args
[
0
]
print
(
t
)
print
(
dir
(
t
))
print
(
type
(
t
))
print
(
repr
(
t
))
print
(
str
(
t
))
#print(help(t))
print
(
't.name: %r'
%
t
.
name
)
print
(
't.addr: %s'
%
hex
(
t
.
addr
))
print
(
't.type: %r'
%
t
.
type
)
print
(
't.function: %r'
%
t
.
function
)
#print(help(t.function))
print
(
't.type.type: %r'
%
t
.
type
.
type
)
loc
=
t
.
location
print
(
loc
)
print
(
dir
(
loc
))
print
(
type
(
loc
))
print
(
repr
(
loc
))
#print(help(loc))
print
(
'loc.file: %r'
%
loc
.
file
)
print
(
'loc.line: %r'
%
loc
.
line
)
# raise RuntimeError('what happens if we get an error here?')
gcc
.
register_callback
(
gcc
.
PLUGIN_PASS_EXECUTION
,
my_pass_execution_callback
)
gcc
.
register_callback
(
gcc
.
PLUGIN_PRE_GENERICIZE
,
my_pre_genericize_callback
)
# Try some insane values:
#gcc.register_callback(-1, my_callback)
# Stupid hack idea: a UI for gcc:
#import gtk
#w = gtk.Window(gtk.WINDOW_TOPLEVEL)
#w.show()
#gtk.main()
#from pprint import pprint
#pprint(tree.subclass_for_code)
You can’t perform that action at this time.