Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,44 @@ mod varargs;
mod vla;

pub struct AstBuilderImpl<'a> {
// Input and diagnostics.
error_logger: &'a dyn error::ErrorLogger,
tokens: &'a Vec<Token>,
cur: usize,
offset_size: usize,
loop_stack: Vec<usize>,
labels: HashMap<String, usize>,
defined_labels: HashSet<String>,
switch_stack: Vec<Vec<Node>>,
switch_types: Vec<Type>,
return_type: Option<Type>,

// Scopes, types and declaration context.
scope_stack: Vec<HashMap<String, Identifier>>,
struct_definitions: Vec<Rc<RefCell<StructDefinition>>>,
next_enum_id: usize,
declaration_attributes_state: Option<DeclarationAttributes>,
parameter_depth: usize,

// Current function.
current_function: Option<Token>,
mutable_static: Option<Token>,
return_type: Option<Type>,
return_pointer: Option<usize>,
mutable_static: Option<Token>,
variadic_parameters: Option<Vec<Type>>,
variadic_last: Option<usize>,

// Local storage and variable-length arrays.
offset_size: usize,
next_deferred_local: usize,
pending_bounds: Vec<Node>,
parameter_depth: usize,
declaration_attributes_state: Option<DeclarationAttributes>,
dynamic_objects: Vec<Node>,
vla_active: Vec<usize>,
jump_depths: Vec<usize>,

// Control flow and jump lifetimes.
loop_stack: Vec<usize>,
continue_depths: HashMap<usize, usize>,
switch_stack: Vec<Vec<Node>>,
switch_types: Vec<Type>,
switch_vla_depths: Vec<usize>,
next_enum_id: usize,
next_deferred_local: usize,
struct_definitions: Vec<Rc<RefCell<StructDefinition>>>,
scope_stack: Vec<HashMap<String, Identifier>>,
labels: HashMap<String, usize>,
defined_labels: HashSet<String>,
jump_depths: Vec<usize>,

// Translation-unit output.
pub functions: HashMap<String, Func>,
pub global_variables: HashMap<String, GlobalVariable>,
pub string_literals: Vec<Token>,
Expand All @@ -71,16 +82,17 @@ pub struct ProgramAst<'a> {

pub enum Identifier {
TypeDef(Type),
Constant(i64, Type),
EnumTag {
ty: Type,
fixed: bool,
defined: bool,
},
StaticObject(Type, String),
Constant(i64, Type),

Local(Type, usize, bool, usize),
Dynamic(Type, usize, bool),
Static(Type),
StaticObject(Type, String),
}

#[derive(Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -165,14 +177,16 @@ impl Declarator {

#[derive(Clone, Default)]
struct DeclarationAttributes {
typedef_declarator: bool,
word_mode: bool,
vector_size: Option<usize>,
transparent_union: bool,

gnu_inline: bool,
noinline: bool,
weak_import: bool,

common: bool,
typedef_declarator: bool,
transparent_union: bool,
vector_size: Option<usize>,
word_mode: bool,
weak_import: bool,
hidden: bool,
}

Expand Down
15 changes: 9 additions & 6 deletions src/bin/dynamite-cc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ enum LinkArgument {
}

struct Arguments {
mode: Mode,
preprocess_only: bool,
emit_llvm: bool,
jobs: usize,

inputs: Vec<Input>,
output: Option<String>,

preprocessing: Vec<String>,
backend: Vec<String>,
linker: Vec<LinkArgument>,
preprocessing: Vec<String>,
forwarded: Vec<String>,
output: Option<String>,
mode: Mode,
jobs: usize,

dependencies: Option<bool>,
dependency_file: Option<String>,
dependency_targets: Vec<String>,
phony_dependencies: bool,
preprocess_only: bool,
emit_llvm: bool,
}

struct TemporaryDirectory(PathBuf);
Expand Down
40 changes: 24 additions & 16 deletions src/ctype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ pub struct StructType {
#[derive(Default)]
pub struct StructDefinition {
pub members: Vec<StructMember>,
pub complete: bool,
pub is_union: bool,
/// Function parameters use the first scalar member's calling convention.
pub transparent_union: bool,
pub has_bit_fields: bool,
pub has_flexible_array: bool,

pub size: usize,
pub align: usize,
/// Member-derived alignment before record-level alignment attributes.
pub natural_align: usize,
/// Packed storage marker: a pragma limit, or 1 for GNU packed records.
pub packing: Option<usize>,
pub complete: bool,
}

#[derive(Clone, Copy, Debug)]
Expand All @@ -58,12 +59,14 @@ pub struct BitField {
#[derive(Clone, Debug)]
pub struct StructMember {
pub name: String,
pub anonymous: bool,
/// Explicit member alignment before record packing is applied.
pub requested_alignment: usize,
pub ty: Type,

pub offset: usize,
/// Explicit member alignment before record packing is applied.
pub requested_alignment: usize,
pub bit_field: Option<BitField>,

pub anonymous: bool,
}

impl StructType {
Expand Down Expand Up @@ -147,38 +150,43 @@ impl fmt::Debug for StructType {
/// Recursive type components are shared; lowering uses copy-on-write mutations.
#[derive(Clone, PartialEq, Debug)]
pub enum Type {
// Scalar types.
Void,
Qualified(Rc<Type>, Qualifiers),
/// Object alignment supplied by a scalar typedef, independent of type identity.
Aligned(Rc<Type>, usize),
Struct(StructType),
Enum(EnumType),
Bool,
I8,
SignedChar,
I32,
LongLong {
Integer {
bits: u8,
signed: bool,
},
Integer128 {
LongLong {
signed: bool,
},
Integer {
bits: u8,
Integer128 {
signed: bool,
},
Bool,
Enum(EnumType),
Float16,
/// Vector element type and lane count; value operations are not yet supported.
Vector(Rc<Type>, usize),
Float(u8),
LongDouble(u8),

// Derived and aggregate types.
Ptr(Rc<Type>),
/// None denotes an omitted bound; Some(0) is a complete GNU zero-length array.
Arr(Rc<Type>, Option<usize>),
// The offset names the captured bound; runtime_size computes the language size.
Vla(Rc<Type>, usize),
/// Vector element type and lane count; value operations are not yet supported.
Vector(Rc<Type>, usize),
Struct(StructType),
Func(Rc<Vec<Type>>, Rc<Type>),
VariadicFunc(Rc<Vec<Type>>, Rc<Type>),

// Type wrappers.
Qualified(Rc<Type>, Qualifiers),
/// Object alignment supplied by a scalar typedef, independent of type identity.
Aligned(Rc<Type>, usize),
}

impl Type {
Expand Down
21 changes: 12 additions & 9 deletions src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ use crate::token::Token;

#[derive(Default)]
pub struct Func {
pub token: Option<Token>,
pub cty: Type,
pub args: Vec<Node>,
pub body: Option<Node>,
pub mutable_static: Option<Token>,

pub offset_size: usize,
pub return_pointer: Option<usize>,

pub internal: bool,
pub external_definition: bool,
pub weak_import: bool,
pub hidden: bool,

pub inline_definition: bool,
pub gnu_inline: bool,
pub noinline: bool,
pub weak_import: bool,
pub hidden: bool,
pub external_definition: bool,
pub mutable_static: Option<Token>,
pub return_pointer: Option<usize>,
pub cty: Type,
pub offset_size: usize,
pub token: Option<Token>,
pub args: Vec<Node>,
}

impl Func {
Expand Down
Loading
Loading