initial draft
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package ir
|
||||
|
||||
import "../source"
|
||||
import "../types"
|
||||
import "core:mem"
|
||||
|
||||
INVALID_ID :: -1
|
||||
|
||||
Opcode :: enum {
|
||||
Param,
|
||||
Const,
|
||||
Load_Global,
|
||||
Alloca,
|
||||
Load,
|
||||
Store,
|
||||
Widen,
|
||||
Add_Checked,
|
||||
Call,
|
||||
Trap,
|
||||
Return,
|
||||
Return_Void,
|
||||
}
|
||||
|
||||
Instruction :: struct {
|
||||
op: Opcode,
|
||||
span: source.Span,
|
||||
type: types.Type,
|
||||
integer: i64,
|
||||
target: int,
|
||||
a: int,
|
||||
b: int,
|
||||
args: []int,
|
||||
diagnostic: int,
|
||||
}
|
||||
|
||||
Function :: struct {
|
||||
name: string,
|
||||
link_name: string,
|
||||
c_abi: bool,
|
||||
is_main: bool,
|
||||
param_types: []types.Type,
|
||||
result: types.Type,
|
||||
instructions: []Instruction,
|
||||
problematic: bool,
|
||||
}
|
||||
|
||||
Global :: struct {
|
||||
name: string,
|
||||
type: types.Type,
|
||||
is_static: bool,
|
||||
static_value: i64,
|
||||
initializer: []Instruction,
|
||||
problematic: bool,
|
||||
diagnostic: int,
|
||||
}
|
||||
|
||||
Module :: struct {
|
||||
functions: [dynamic]Function,
|
||||
globals: [dynamic]Global,
|
||||
allocator: mem.Allocator,
|
||||
}
|
||||
|
||||
init_module :: proc(allocator := context.allocator) -> Module {
|
||||
module: Module
|
||||
module.functions.allocator = allocator
|
||||
module.globals.allocator = allocator
|
||||
module.allocator = allocator
|
||||
return module
|
||||
}
|
||||
|
||||
destroy_instructions :: proc(instructions: []Instruction, allocator: mem.Allocator) {
|
||||
for instruction in instructions {
|
||||
delete(instruction.args, allocator)
|
||||
}
|
||||
delete(instructions, allocator)
|
||||
}
|
||||
|
||||
destroy_module :: proc(module: ^Module) {
|
||||
for function in module.functions {
|
||||
delete(function.name, module.allocator)
|
||||
delete(function.link_name, module.allocator)
|
||||
delete(function.param_types, module.allocator)
|
||||
destroy_instructions(function.instructions, module.allocator)
|
||||
}
|
||||
for global in module.globals {
|
||||
delete(global.name, module.allocator)
|
||||
destroy_instructions(global.initializer, module.allocator)
|
||||
}
|
||||
delete(module.functions)
|
||||
delete(module.globals)
|
||||
}
|
||||
Reference in New Issue
Block a user