-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6363bbb
commit c2bf267
Showing
1 changed file
with
65 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,82 @@ | ||
from pprint import pprint | ||
import json | ||
import sys | ||
|
||
sys.setrecursionlimit(5000) | ||
with open('ssdt.dsl', 'r') as f: | ||
ssdt = f.readlines() | ||
|
||
externals = [] | ||
methods = [] | ||
offsets = [] | ||
variables = [] | ||
op_regs = [] | ||
|
||
tree = {} | ||
|
||
skipped_fields = ( | ||
externals = [] | ||
methods = [] | ||
offsets = [] | ||
variables = [] | ||
op_regs = [] | ||
|
||
'/*', | ||
'*', | ||
) | ||
tree = {'DSDT': {}} | ||
tree['DSDT']['Devices'] = [] | ||
tree['DSDT']['Methods'] = [] | ||
tree['DSDT']['Names'] = [] | ||
tree['DSDT']['OpRegs'] = [] | ||
|
||
skipped_fields = ( | ||
|
||
for lines in ssdt: | ||
current_line = lines.strip() | ||
if current_line.startswith(skipped_fields): | ||
continue | ||
'/*', | ||
'*', | ||
'//', | ||
) | ||
|
||
if current_line.startswith('DefinitionBlock'): | ||
print(f"Definition Block stuff:\n\n\tTableSignature: {current_line.split()[2][1:-2]}\n\tComplianceRevision: {current_line.split()[3][:-1]}\n\tOEMID: {current_line.split()[4][1:]}\n\tTableID: {current_line.split()[6][1:]}\n\tOEMRevision: {current_line.split()[8][:-1]}\n") | ||
current_scope = '' | ||
|
||
if current_line.startswith('External'): | ||
external_object_name = current_line.split()[1][1:-1] | ||
external_object_type = current_line.split()[2][0:-1] | ||
external_object = { | ||
'name': external_object_name, | ||
'type': external_object_type | ||
} | ||
externals.append(external_object) | ||
print(f"External reference found! {external_object_name} is a {external_object_type}") | ||
for lines in ssdt: | ||
current_line = lines.strip() | ||
|
||
if current_line.startswith(skipped_fields): | ||
continue | ||
|
||
with open('output.json', 'w') as f: | ||
json.dump(externals, f, indent=4) | ||
|
||
print(externals) | ||
# for lines in ssdt: | ||
# current_line = lines.strip() | ||
# if list(current_line) == []: # skips empty line | ||
# continue | ||
|
||
# if current_line.startswith(skipped_fields): | ||
# continue | ||
if current_line.startswith('DefinitionBlock'): | ||
print(f"\nDefinition Block stuff:\n\n\tTableSignature: {current_line.split()[2][1:-2]}\n\tComplianceRevision: {current_line.split()[3][:-1]}\n\tOEMID: {current_line.split()[4][1:]}\n\tTableID: {current_line.split()[6][1:]}\n\tOEMRevision: {current_line.split()[8][:-1]}\n") | ||
|
||
# if current_line.startswith('External'): | ||
# external_object_name = current_line.split()[1][1:-1] | ||
# external_object_type = current_line.split()[2][0:-1] | ||
# external_object = { | ||
# 'name': external_object_name, | ||
# 'type': external_object_type | ||
# } | ||
# externals.append(external_object) | ||
|
||
# if current_line.startswith('Name'): | ||
# print(current_line) | ||
# var_name = current_line.split()[1][1:-1] | ||
# var_value = '' | ||
# match var_name: | ||
# case '_HID': | ||
# if current_line.split()[2].startswith('EisaId'): | ||
# var_value = f"EisaId ({current_line.split()[3][1:-1].strip(')')})" | ||
# else: | ||
# var_value = current_line.split()[2][0:-1].strip(')') | ||
if current_line.startswith('External'): | ||
external_object_name = current_line.split()[1][1:-1] | ||
external_object_type = current_line.split()[2][0:-1] | ||
external_object = { | ||
'name': external_object_name, | ||
'type': external_object_type | ||
} | ||
externals.append(external_object) | ||
|
||
if current_line.startswith('Name'): | ||
var_name = current_line.split()[1][1:-1] | ||
var_value = '' | ||
match var_name: | ||
case '_HID': | ||
if current_line.split()[2].startswith('EisaId'): | ||
var_value = f"EisaId ({current_line.split()[3][1:-1].strip(')')})" | ||
else: | ||
var_value = current_line.split()[2][0:-1].strip(')') | ||
case _: | ||
var_value = current_line.split()[-1][:-1] | ||
|
||
# var = { | ||
# 'name': var_name, | ||
# 'value': var_value | ||
# } | ||
# variables.append(var) | ||
if current_line.startswith('Scope'): | ||
current_scope = current_line.strip().split()[1][1:-1].split('.') #will be a list | ||
current_object = tree | ||
|
||
|
||
# pprint(variables) | ||
for breadcrumb in current_scope: | ||
try: | ||
current_object = current_object[breadcrumb] | ||
except KeyError: | ||
current_object[breadcrumb] = dict() | ||
current_object = current_object[breadcrumb] | ||
|
||
last_scope = current_object | ||
|
||
if current_line.startswith('Device'): | ||
device_name = current_line.strip().split()[1][1:-1] | ||
current_object = tree | ||
for breadcrumb in current_scope: | ||
current_object = current_object[breadcrumb] | ||
if breadcrumb == current_scope[-1]: | ||
current_object[device_name] = dict() | ||
pprint(tree) | ||
|
||
|