compact compiler ids and spans to reduce memory usage
This commit is contained in:
+54
-12
@@ -5,24 +5,66 @@ import "../symbol"
|
||||
import "../types"
|
||||
import "core:mem"
|
||||
|
||||
INVALID_ID :: -1
|
||||
Instruction_Id :: distinct u32
|
||||
Local_Id :: distinct u32
|
||||
Function_Id :: distinct u32
|
||||
Global_Id :: distinct u32
|
||||
Ref :: distinct u32
|
||||
|
||||
Calling_Convention :: enum {
|
||||
INVALID_INSTRUCTION :: Instruction_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)
|
||||
|
||||
instruction_id :: proc(index: int) -> Instruction_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_INSTRUCTION))
|
||||
return Instruction_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,
|
||||
}
|
||||
|
||||
Opcode :: enum {
|
||||
Opcode :: enum u8 {
|
||||
Param,
|
||||
Const,
|
||||
Load_Global,
|
||||
@@ -38,15 +80,15 @@ Opcode :: enum {
|
||||
}
|
||||
|
||||
Instruction :: struct {
|
||||
op: Opcode,
|
||||
span: source.Span,
|
||||
type: types.Type,
|
||||
integer: i64,
|
||||
target: int,
|
||||
a: int,
|
||||
b: int,
|
||||
args: []int,
|
||||
diagnostic: int,
|
||||
args: []Instruction_Id,
|
||||
target: Ref,
|
||||
a: Instruction_Id,
|
||||
b: Instruction_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
op: Opcode,
|
||||
}
|
||||
|
||||
Function :: struct {
|
||||
@@ -68,7 +110,7 @@ Global :: struct {
|
||||
static_value: i64,
|
||||
initializer: []Instruction,
|
||||
problematic: bool,
|
||||
diagnostic: int,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
|
||||
Module :: struct {
|
||||
|
||||
Reference in New Issue
Block a user