initial draft
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
package hir
|
||||
|
||||
import "../source"
|
||||
import "../types"
|
||||
import "core:mem"
|
||||
|
||||
INVALID_ID :: -1
|
||||
|
||||
Expr_Kind :: enum {
|
||||
Invalid,
|
||||
Integer,
|
||||
Local,
|
||||
Global,
|
||||
Widen,
|
||||
Add,
|
||||
Call,
|
||||
}
|
||||
|
||||
Expr :: struct {
|
||||
kind: Expr_Kind,
|
||||
span: source.Span,
|
||||
type: types.Type,
|
||||
integer: i64,
|
||||
target: int,
|
||||
left: int,
|
||||
right: int,
|
||||
args: []int,
|
||||
diagnostic: int,
|
||||
}
|
||||
|
||||
Local :: struct {
|
||||
name: string,
|
||||
type: types.Type,
|
||||
mutable: bool,
|
||||
parameter: bool,
|
||||
}
|
||||
|
||||
Stmt_Kind :: enum {
|
||||
Declaration,
|
||||
Assignment,
|
||||
Return,
|
||||
Expression,
|
||||
Sink,
|
||||
Trap,
|
||||
}
|
||||
|
||||
Stmt :: struct {
|
||||
kind: Stmt_Kind,
|
||||
span: source.Span,
|
||||
local: int,
|
||||
expr: int,
|
||||
diagnostic: int,
|
||||
}
|
||||
|
||||
Function :: struct {
|
||||
name: string,
|
||||
link_name: string,
|
||||
c_abi: bool,
|
||||
is_main: bool,
|
||||
params: []int,
|
||||
result: types.Type,
|
||||
locals: []Local,
|
||||
body: []int,
|
||||
direct_global_reads: []int,
|
||||
calls: []int,
|
||||
problematic: bool,
|
||||
diagnostic: int,
|
||||
}
|
||||
|
||||
Global :: struct {
|
||||
name: string,
|
||||
type: types.Type,
|
||||
expr: int,
|
||||
static_value: i64,
|
||||
is_static: bool,
|
||||
dependencies: []int,
|
||||
calls: []int,
|
||||
direct_problem: bool,
|
||||
problematic: bool,
|
||||
diagnostic: int,
|
||||
}
|
||||
|
||||
Module :: struct {
|
||||
exprs: [dynamic]Expr,
|
||||
statements: [dynamic]Stmt,
|
||||
functions: [dynamic]Function,
|
||||
globals: [dynamic]Global,
|
||||
allocator: mem.Allocator,
|
||||
}
|
||||
|
||||
init_module :: proc(allocator := context.allocator) -> Module {
|
||||
module: Module
|
||||
module.allocator = allocator
|
||||
module.exprs.allocator = allocator
|
||||
module.statements.allocator = allocator
|
||||
module.functions.allocator = allocator
|
||||
module.globals.allocator = allocator
|
||||
return module
|
||||
}
|
||||
|
||||
destroy_module :: proc(module: ^Module) {
|
||||
for expr in module.exprs {
|
||||
delete(expr.args, module.allocator)
|
||||
}
|
||||
for function in module.functions {
|
||||
delete(function.link_name, module.allocator)
|
||||
delete(function.params, module.allocator)
|
||||
delete(function.locals, module.allocator)
|
||||
delete(function.body, module.allocator)
|
||||
delete(function.direct_global_reads, module.allocator)
|
||||
delete(function.calls, module.allocator)
|
||||
}
|
||||
for global in module.globals {
|
||||
delete(global.dependencies, module.allocator)
|
||||
delete(global.calls, module.allocator)
|
||||
}
|
||||
delete(module.exprs)
|
||||
delete(module.statements)
|
||||
delete(module.functions)
|
||||
delete(module.globals)
|
||||
}
|
||||
Reference in New Issue
Block a user