mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[build] Change memory_layout from csv to yaml
I realized we don't need yet another format for configuration. As a bonus, yaml also allows for a more descriptive file.
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
linear,64T,shared
|
||||
bitmap,1T,shared
|
||||
heap,64G
|
||||
stacks,64G
|
||||
buffers,64G
|
||||
|
17
definitions/memory_layout.yaml
Normal file
17
definitions/memory_layout.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- name: linear
|
||||
size: 64T
|
||||
shared: true
|
||||
|
||||
- name: bitmap
|
||||
size: 1T
|
||||
shared: true
|
||||
|
||||
- name: heap
|
||||
size: 64G
|
||||
|
||||
- name: stacks
|
||||
size: 64G
|
||||
|
||||
- name: buffers
|
||||
size: 64G
|
||||
@@ -4,27 +4,29 @@ class Layout:
|
||||
|
||||
sizes = {'G': 1024 ** 3, 'T': 1024 ** 4}
|
||||
|
||||
def __init__(self, path):
|
||||
import csv
|
||||
|
||||
regions = []
|
||||
addr = 1 << 64
|
||||
|
||||
with open(path, newline='') as infile:
|
||||
reader = csv.reader(infile)
|
||||
for row in reader:
|
||||
name, size = row[:2]
|
||||
shared = (len(row) > 2 and "shared" in row[2])
|
||||
|
||||
size, mag = int(size[:-1]), size[-1]
|
||||
@staticmethod
|
||||
def get_size(desc):
|
||||
size, mag = int(desc[:-1]), desc[-1]
|
||||
|
||||
try:
|
||||
mult = Layout.sizes[mag]
|
||||
except KeyError:
|
||||
raise RuntimeError(f"No magnitude named '{mag}'.")
|
||||
|
||||
size *= mult
|
||||
return size * mult
|
||||
|
||||
def __init__(self, path):
|
||||
from yaml import safe_load
|
||||
|
||||
regions = []
|
||||
addr = 1 << 64
|
||||
|
||||
with open(path, 'r') as infile:
|
||||
data = safe_load(infile.read())
|
||||
for r in data:
|
||||
size = Layout.get_size(r["size"])
|
||||
addr -= size
|
||||
regions.append(Layout.Region(name, addr, size, shared))
|
||||
regions.append(Layout.Region(r["name"], addr, size,
|
||||
r.get("shared", False)))
|
||||
|
||||
self.regions = tuple(regions)
|
||||
|
||||
@@ -68,7 +68,7 @@ kernel = module("kernel",
|
||||
from glob import glob
|
||||
from os.path import join
|
||||
|
||||
layout = join(source_root, "definitions/memory_layout.csv")
|
||||
layout = join(source_root, "definitions/memory_layout.yaml")
|
||||
definitions = glob('definitions/**/*.def', recursive=True)
|
||||
|
||||
kernel.add_depends(["memory.h.cog"], [layout])
|
||||
|
||||
@@ -37,7 +37,7 @@ constexpr unsigned kernel_buffer_pages = 16;
|
||||
from os.path import join
|
||||
from memory import Layout
|
||||
|
||||
layout = Layout(join(definitions_path, "memory_layout.csv"))
|
||||
layout = Layout(join(definitions_path, "memory_layout.yaml"))
|
||||
l = max([len(r.name) for r in layout.regions])
|
||||
|
||||
for region in layout.regions:
|
||||
|
||||
@@ -8,5 +8,5 @@ bp = module("bootproto",
|
||||
|
||||
from os.path import join
|
||||
|
||||
layout = join(source_root, "definitions/memory_layout.csv")
|
||||
layout = join(source_root, "definitions/memory_layout.yaml")
|
||||
bp.add_input("include/bootproto/memory.h.cog", deps=[layout])
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace mem {
|
||||
from os.path import join
|
||||
from memory import Layout
|
||||
|
||||
layout = Layout(join(definitions_path, "memory_layout.csv"))
|
||||
layout = Layout(join(definitions_path, "memory_layout.yaml"))
|
||||
|
||||
for region in layout.regions:
|
||||
if region.shared:
|
||||
|
||||
Reference in New Issue
Block a user