Skip to content

Commit e49be68

Browse files
committed
Restructuring so that eventually utils.py can be called wrappers.py
1 parent 5d91799 commit e49be68

File tree

7 files changed

+481
-453
lines changed

7 files changed

+481
-453
lines changed

wllvm/arglistfilter.py

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.

wllvm/as.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
from wllvm.popenwrapper import Popen
3838

39+
from wllvm.argumentlistfilter import ArgumentListFilter
40+
3941
import logging
4042
logging.basicConfig()
4143

wllvm/extraction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import subprocess as sp
44

55
from utils import llvmCompilerPathEnv
6+
67
from popenwrapper import Popen
8+
79
from utils import elfSectionName
810
from utils import darwinSegmentName
911
from utils import darwinSectionName
10-
from utils import FileType
12+
13+
from filetype import FileType
1114

1215
import logconfig
1316

wllvm/filetype.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
3+
from subprocess import *
4+
5+
from .popenwrapper import Popen
6+
7+
# Static class that allows the type of a file to be checked.
8+
class FileType(object):
9+
# Provides int -> str map
10+
revMap = { }
11+
12+
@classmethod
13+
def getFileType(cls, fileName):
14+
# This is a hacky way of determining
15+
# the type of file we are looking at.
16+
# Maybe we should use python-magic instead?
17+
18+
fileP = Popen(['file',os.path.realpath(fileName)], stdout=PIPE)
19+
output = fileP.communicate()[0]
20+
output = output.decode()
21+
if 'ELF' in output and 'executable' in output:
22+
return cls.ELF_EXECUTABLE
23+
if 'Mach-O' in output and 'executable' in output:
24+
return cls.MACH_EXECUTABLE
25+
elif 'ELF' in output and 'shared' in output:
26+
return cls.ELF_SHARED
27+
elif 'Mach-O' in output and 'dynamically linked shared' in output:
28+
return cls.MACH_SHARED
29+
elif 'current ar archive' in output:
30+
return cls.ARCHIVE
31+
elif 'ELF' in output and 'relocatable' in output:
32+
return cls.ELF_OBJECT
33+
elif 'Mach-O' in output and 'object' in output:
34+
return cls.MACH_OBJECT
35+
else:
36+
return cls.UNKNOWN
37+
38+
@classmethod
39+
def init(cls):
40+
for (index, name) in enumerate(('UNKNOWN',
41+
'ELF_EXECUTABLE',
42+
'ELF_OBJECT',
43+
'ELF_SHARED',
44+
'MACH_EXECUTABLE',
45+
'MACH_OBJECT',
46+
'MACH_SHARED',
47+
'ARCHIVE')):
48+
setattr(cls, name, index)
49+
cls.revMap[index] = name
50+
51+
# Initialise FileType static class
52+
FileType.init()

0 commit comments

Comments
 (0)