compact compiler ids and spans to reduce memory usage
This commit is contained in:
+73
-24
@@ -5,24 +5,73 @@ import "../symbol"
|
||||
import "../types"
|
||||
import "core:mem"
|
||||
|
||||
INVALID_ID :: -1
|
||||
Expr_Id :: distinct u32
|
||||
Stmt_Id :: distinct u32
|
||||
Local_Id :: distinct u32
|
||||
Function_Id :: distinct u32
|
||||
Global_Id :: distinct u32
|
||||
Ref :: distinct u32
|
||||
|
||||
Calling_Convention :: enum {
|
||||
INVALID_EXPR :: Expr_Id(0xffff_ffff)
|
||||
INVALID_STMT :: Stmt_Id(0xffff_ffff)
|
||||
INVALID_LOCAL :: Local_Id(0xffff_ffff)
|
||||
INVALID_FUNCTION :: Function_Id(0xffff_ffff)
|
||||
INVALID_GLOBAL :: Global_Id(0xffff_ffff)
|
||||
INVALID_REF :: Ref(0xffff_ffff)
|
||||
|
||||
expr_id :: proc(index: int) -> Expr_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_EXPR))
|
||||
return Expr_Id(index)
|
||||
}
|
||||
|
||||
stmt_id :: proc(index: int) -> Stmt_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_STMT))
|
||||
return Stmt_Id(index)
|
||||
}
|
||||
|
||||
local_id :: proc(index: int) -> Local_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_LOCAL))
|
||||
return Local_Id(index)
|
||||
}
|
||||
|
||||
function_id :: proc(index: int) -> Function_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_FUNCTION))
|
||||
return Function_Id(index)
|
||||
}
|
||||
|
||||
global_id :: proc(index: int) -> Global_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_GLOBAL))
|
||||
return Global_Id(index)
|
||||
}
|
||||
|
||||
index :: proc(id: $T, invalid: T, count: int) -> (int, bool) {
|
||||
value := int(id)
|
||||
return value, id != invalid && value < count
|
||||
}
|
||||
|
||||
local_ref :: proc(id: Local_Id) -> Ref {return Ref(id)}
|
||||
function_ref :: proc(id: Function_Id) -> Ref {return Ref(id)}
|
||||
global_ref :: proc(id: Global_Id) -> Ref {return Ref(id)}
|
||||
as_local :: proc(ref: Ref) -> Local_Id {return Local_Id(ref)}
|
||||
as_function :: proc(ref: Ref) -> Function_Id {return Function_Id(ref)}
|
||||
as_global :: proc(ref: Ref) -> Global_Id {return Global_Id(ref)}
|
||||
|
||||
Calling_Convention :: enum u8 {
|
||||
Brolang,
|
||||
C,
|
||||
}
|
||||
|
||||
Implementation :: enum {
|
||||
Implementation :: enum u8 {
|
||||
Definition,
|
||||
Declaration,
|
||||
}
|
||||
|
||||
Linkage :: enum {
|
||||
Linkage :: enum u8 {
|
||||
Internal,
|
||||
External,
|
||||
}
|
||||
|
||||
Expr_Kind :: enum {
|
||||
Expr_Kind :: enum u8 {
|
||||
Invalid,
|
||||
Integer,
|
||||
Local,
|
||||
@@ -33,15 +82,15 @@ Expr_Kind :: enum {
|
||||
}
|
||||
|
||||
Expr :: struct {
|
||||
kind: Expr_Kind,
|
||||
span: source.Span,
|
||||
type: types.Type,
|
||||
integer: i64,
|
||||
target: int,
|
||||
left: int,
|
||||
right: int,
|
||||
args: []int,
|
||||
diagnostic: int,
|
||||
args: []Expr_Id,
|
||||
target: Ref,
|
||||
left: Expr_Id,
|
||||
right: Expr_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
kind: Expr_Kind,
|
||||
}
|
||||
|
||||
Local :: struct {
|
||||
@@ -51,7 +100,7 @@ Local :: struct {
|
||||
parameter: bool,
|
||||
}
|
||||
|
||||
Stmt_Kind :: enum {
|
||||
Stmt_Kind :: enum u8 {
|
||||
Declaration,
|
||||
Assignment,
|
||||
Return,
|
||||
@@ -63,9 +112,9 @@ Stmt_Kind :: enum {
|
||||
Stmt :: struct {
|
||||
kind: Stmt_Kind,
|
||||
span: source.Span,
|
||||
local: int,
|
||||
expr: int,
|
||||
diagnostic: int,
|
||||
local: Local_Id,
|
||||
expr: Expr_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
|
||||
Function :: struct {
|
||||
@@ -75,27 +124,27 @@ Function :: struct {
|
||||
implementation: Implementation,
|
||||
linkage: Linkage,
|
||||
is_main: bool,
|
||||
params: []int,
|
||||
params: []Local_Id,
|
||||
result: types.Type,
|
||||
locals: []Local,
|
||||
body: []int,
|
||||
direct_global_reads: [dynamic]int,
|
||||
calls: []int,
|
||||
body: []Stmt_Id,
|
||||
direct_global_reads: [dynamic]Global_Id,
|
||||
calls: []Function_Id,
|
||||
problematic: bool,
|
||||
diagnostic: int,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
|
||||
Global :: struct {
|
||||
name: symbol.Id,
|
||||
type: types.Type,
|
||||
expr: int,
|
||||
expr: Expr_Id,
|
||||
static_value: i64,
|
||||
is_static: bool,
|
||||
dependencies: [dynamic]int,
|
||||
calls: []int,
|
||||
dependencies: [dynamic]Global_Id,
|
||||
calls: []Function_Id,
|
||||
direct_problem: bool,
|
||||
problematic: bool,
|
||||
diagnostic: int,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
|
||||
Module :: struct {
|
||||
|
||||
Reference in New Issue
Block a user