Skip to content
Open
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
39 changes: 20 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,33 @@ jobs:
- name: bootstrap + compile
run: |
. env.sh
make globals
make all

- name: run unit-tests
run: |
. env.sh
make test

# linux-32bits:
# name: Linux 32-bits
# runs-on: ubuntu-latest
# defaults:
# run:
# shell: alpine.sh {0}
# steps:
# - uses: actions/checkout@v6
# - uses: jirutka/setup-alpine@v1
# with:
# arch: x86
# packages: "build-base make"
# - name: header dump
# run: make globals CONFIG_32BIT=y
# - name: bootstrap + compile + tests
# run: |
# . env.sh
# make all test CONFIG_32BIT=y
linux-32bits:
name: Linux 32-bits
runs-on: ubuntu-latest
defaults:
run:
shell: alpine.sh {0}
steps:
- uses: actions/checkout@v6
- uses: jirutka/setup-alpine@v1
with:
arch: x86
packages: "build-base make"
- name: header dump
run: |
. env.sh
make globals CONFIG_32BIT=y
- name: bootstrap + compile + tests
run: |
. env.sh
make all test CONFIG_32BIT=y

macos:
name: macOS
Expand Down
26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ ifdef DEBUG
# should be --debug
C2FLAGS+= --fast
endif
ifdef CONFIG_32BIT
MAKEFLAGS+= CONFIG_32BIT=y
ifeq (y,$(CONFIG_M32))
# Probably useless
MAKEFLAGS+= CONFIG_M32=y
C2FLAGS32+= -m32
endif

C2C_DIRS:= {analyser,analyser_utils,ast,ast_utils,common,compiler,generator,ir,libs,parser}
Expand All @@ -33,16 +35,16 @@ $(C2C): output/bootstrap/bootstrap $(C2C_DEPS)
@output/bootstrap/bootstrap c2c $(C2FLAGS) --fast --noplugins
@rm -rf output/bootstrap/cgen
@mv -f output/c2c/* output/bootstrap
@echo "---- running c2c (no plugins$(C2FLAGS)) ----"
@output/bootstrap/c2c $(C2FLAGS) --noplugins --fast --quiet c2c $(PLUGINS)
@echo "---- running c2c (no plugins$(C2FLAGS) $(C2FLAGS32)) ----"
@output/bootstrap/c2c $(C2FLAGS) $(C2FLAGS32) --noplugins --fast --quiet c2c $(PLUGINS)
@mv -f output/c2c/c2c output/c2c/c2c_fast
@./install_plugins.sh
@echo "---- running c2c (optimized with plugins$(C2FLAGS)) ----"
@output/c2c/c2c_fast $(C2FLAGS) --quiet
@echo "---- running c2c (optimized with plugins$(C2FLAGS) $(C2FLAGS32)) ----"
@output/c2c/c2c_fast $(C2FLAGS) $(C2FLAGS32) --quiet
@./install_plugins.sh

output/bootstrap/bootstrap:
@$(MAKE) -B -C bootstrap $(MAKEFLAGS)
@$(MAKE) -B -C bootstrap CONFIG_M32=n

san:; @$(MAKE) -B ASAN=1 UBSAN=1 $(MAKEFLAGS)
asan:; @$(MAKE) -B ASAN=1 $(MAKEFLAGS)
Expand All @@ -60,10 +62,12 @@ rebuild-bootstrap: $(C2C)
@echo "generating bootstrap files for various systems/architectures"
$(C2C) c2c -b bootstrap/build-linux-x86_64.yaml --no-build --bootstrap --quiet
mv -f output/linux-x86_64/c2c/cgen/build.c bootstrap/bootstrap.c
$(C2C) c2c -b bootstrap/build-linux-i686.yaml --no-build --bootstrap --quiet
( diff bootstrap/bootstrap.c output/linux-i686/c2c/cgen/build.c > bootstrap/bootstrap-linux-i686.patch ; true )
$(C2C) c2c -b bootstrap/build-darwin-x86_64.yaml --no-build --bootstrap --quiet
( diff bootstrap/bootstrap.c output/darwin-x86_64/c2c/cgen/build.c > bootstrap/bootstrap-darwin-x86_64.patch ; true )
$(C2C) c2c -b bootstrap/build-darwin-arm64.yaml --no-build --bootstrap --quiet
( diff bootstrap/bootstrap.c output/darwin-arm64/c2c/cgen/build.c > bootstrap/bootstrap-darwin-arm64.patch ; true )
( diff bootstrap/bootstrap.c output/darwin-arm64/c2c/cgen/build.c > bootstrap/bootstrap-darwin-arm64.patch ; true )
$(C2C) c2c -b bootstrap/build-freebsd-amd64.yaml --no-build --bootstrap --quiet
( diff bootstrap/bootstrap.c output/freebsd-amd64/c2c/cgen/build.c > bootstrap/bootstrap-freebsd-amd64.patch ; true )
$(C2C) c2c -b bootstrap/build-openbsd-amd64.yaml --no-build --bootstrap --quiet
Expand All @@ -81,16 +85,16 @@ testv: output/tester/tester
@output/tester/tester -v test

output/c2c_trace/c2c_trace: $(C2C_DEPS)
$(C2C) c2c --trace-calls -o c2c_trace --fast --quiet
$(C2C) c2c --trace-calls -o c2c_trace --fast --quiet $(C2FLAGS32)

trace_calls: $(C2C) output/c2c_trace/c2c_trace
C2_TRACE="min=10;min2=1;mode=3;name=*;fd=2" output/c2c_trace/c2c_trace c2c -o c2c_calls --quiet --test 2> output/c2c/calls
C2_TRACE="min=10;min2=1;mode=3;name=*;fd=2" output/c2c_trace/c2c_trace c2c -o c2c_calls --quiet --test $(C2FLAGS32) 2> output/c2c/calls

trace: trace_calls
cat output/c2c/calls

alloc_trace: $(C2C) output/c2c_trace/c2c_trace
C2_TRACE="min=10;min2=1;mode=3;name=stdlib.malloc,stdlib.calloc,stdlib.realloc;fd=2" output/c2c_trace/c2c_trace --quiet c2c -o c2c_alloc --test 2> output/c2c/calls
C2_TRACE="min=10;min2=1;mode=3;name=stdlib.malloc,stdlib.calloc,stdlib.realloc;fd=2" output/c2c_trace/c2c_trace c2c -o c2c_alloc --quiet --test $(C2FLAGS32) 2> output/c2c/calls
cat output/c2c/calls

errors:
Expand Down
18 changes: 14 additions & 4 deletions analyser/module_analyser_call.c2
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,14 @@ fn bool on_printf_specifier(void* context, u32 offset, PrintfSpecifier specifier
ma.error(arg.getStartLoc(), "format '%%%c' expects an integer argument", c);
break;
}
// TODO add ll prefix on LLP targets (64-bit long long and pointers, but 32-bit long)
u32 width = bi.getWidth();
if (width > 32) fa.out.add1('l');
if (width > 32) {
fa.out.add1('l');
if (ma.builder.getNativeLong() == Int32) {
// add ll prefix on targets with 32-bit long
fa.out.add1('l');
}
}
if (c == 'd' && width >= 32 && bi.isUnsigned()) c = 'u';
// Assume target libc supports %b
break;
Expand All @@ -428,10 +433,15 @@ fn bool on_printf_specifier(void* context, u32 offset, PrintfSpecifier specifier
BuiltinType* bi = t.getBuiltinTypeOrNil();
if (bi && bi.isInteger()) {
u32 width = bi.getWidth();
// TODO add ll prefix on LLP targets (64-bit long long and pointers, but 32-bit long)
if (width < 16) fa.out.add1('h');
if (width < 32) fa.out.add1('h');
if (width > 32) fa.out.add1('l');
if (width > 32) {
fa.out.add1('l');
if (ma.builder.getNativeLong() == Int32) {
// add ll prefix on targets with 32-bit long
fa.out.add1('l');
}
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ast/ast.c2
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public type AST struct @(opaque) {
attr_table.Table* attrs;
}

static_assert(144+64, sizeof(AST));
static_assert(sizeof(void*) == 4 ? 132 : 144+64, sizeof(AST));

fn AST* AST.create(string_pool.Pool* auxPool, u32 name, Module* mod, bool is_interface, bool is_generated) {
AST* a = stdlib.calloc(1, sizeof(AST));
Expand Down
4 changes: 2 additions & 2 deletions ast/builtin_type.c2
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public type BuiltinType struct @(opaque) {

fn BuiltinType* BuiltinType.create(ast_context.Context* c, BuiltinKind kind) {
BuiltinKind base_kind = kind;
if (kind == ISize) base_kind = (c.getWordSize() == 4) ? Int32 : Int64;
if (kind == USize) base_kind = (c.getWordSize() == 4) ? UInt32 : UInt64;
if (kind == ISize) base_kind = (c.getPointerSize() == 4) ? Int32 : Int64;
if (kind == USize) base_kind = (c.getPointerSize() == 4) ? UInt32 : UInt64;
BuiltinType* b = c.alloc(sizeof(BuiltinType));
b.base.init(Builtin);
b.base.builtinTypeBits.kind = kind;
Expand Down
2 changes: 1 addition & 1 deletion ast/function_type.c2
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public type FunctionType struct @(opaque) {
fn FunctionType* FunctionType.create(ast_context.Context* c, FunctionDecl* decl) {
FunctionType* t = c.alloc(sizeof(FunctionType));
t.base.init(Function);
t.base.setAlignment(c.getWordSize());
t.base.setAlignment(c.getPointerSize());
t.decl = decl;

t.base.setCanonicalType(QualType.create(&t.base));
Expand Down
2 changes: 1 addition & 1 deletion ast/member_expr.c2
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type MemberRef union {
usize bits;
}

static_assert(8, sizeof(MemberRef));
static_assert(sizeof(void*) == 4 ? 4 : 8, sizeof(MemberRef));

public type MemberExpr struct @(opaque) {
// base.loc points to the beginning of the member name in refs[1]
Expand Down
2 changes: 1 addition & 1 deletion ast/module.c2
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public type Module struct @(opaque) {
SymbolTable symbols;
InstanceTable instances;
}
static_assert(80, sizeof(Module));
static_assert(sizeof(void*) == 4 ? 56 : 80, sizeof(Module));

// Note: name must be allocated in target StringPool
public fn Module* Module.create(ast_context.Context* c, u32 name_idx, bool is_external) {
Expand Down
2 changes: 1 addition & 1 deletion ast/pointer_type.c2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public type PointerType struct @(opaque) {
fn PointerType* PointerType.create(ast_context.Context* c, QualType inner) {
PointerType* t = c.alloc(sizeof(PointerType));
t.base.init(Pointer);
t.base.setAlignment(c.getWordSize());
t.base.setAlignment(c.getPointerSize());
t.inner = inner;
#if AstStatistics
Stats.addType(Pointer, sizeof(PointerType));
Expand Down
2 changes: 1 addition & 1 deletion ast/struct_type_decl.c2
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public type FieldInitField struct {
// 1 byte padding
Decl* decl; // can point to anonymous sub-struct members as well
}
static_assert(24, sizeof(FieldInitField));
static_assert(sizeof(void*) == 4 ? 20 : 24, sizeof(FieldInitField));

public fn bool FieldInitField.isZeroSizeBitfield(const FieldInitField* f) {
return f.is_bitfield && f.bitfield_width == 0;
Expand Down
2 changes: 1 addition & 1 deletion ast/type_ref.c2
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public type Ref struct {
u32 name_idx;
Decl* decl; // set during analysis, or during parsing for Function
}
static_assert(16, sizeof(Ref));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(Ref));

public fn u32 Ref.getNameIdx(const Ref* r) {
return r.name_idx;
Expand Down
94 changes: 47 additions & 47 deletions ast/utils.c2
Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,69 @@ import string;
#if Arch32
#else

static_assert(24, sizeof(Decl));
static_assert(sizeof(void*) == 4 ? 20 : 24, sizeof(Decl));
static_assert(32, sizeof(AliasTypeDecl));
static_assert(64, sizeof(EnumTypeDecl));
static_assert(32, sizeof(FunctionTypeDecl));
static_assert(sizeof(void*) == 4 ? 40 : 64, sizeof(EnumTypeDecl));
static_assert(sizeof(void*) == 4 ? 24 : 32, sizeof(FunctionTypeDecl));
static_assert(32, sizeof(VarDecl));
static_assert(40, sizeof(EnumConstantDecl));
static_assert(40, sizeof(ImportDecl));
static_assert(48, sizeof(StructTypeDecl));
static_assert(80, sizeof(FunctionDecl));
static_assert(sizeof(void*) == 4 ? 32 : 40, sizeof(ImportDecl));
static_assert(sizeof(void*) == 4 ? 36 : 48, sizeof(StructTypeDecl));
static_assert(sizeof(void*) == 4 ? 64 : 80, sizeof(FunctionDecl));

static_assert(8, sizeof(Stmt));
static_assert(12, sizeof(GotoStmt));
static_assert(24, sizeof(LabelStmt));
static_assert(24, sizeof(AssertStmt));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(LabelStmt));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(AssertStmt));
static_assert(8, sizeof(DeclStmt));
static_assert(16, sizeof(SwitchStmt));
static_assert(24, sizeof(AsmStmt));
static_assert(24, sizeof(IfStmt));
static_assert(24, sizeof(WhileStmt));
static_assert(40, sizeof(ForStmt));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(SwitchStmt));
static_assert(sizeof(void*) == 4 ? 20 : 24, sizeof(AsmStmt));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(IfStmt));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(WhileStmt));
static_assert(sizeof(void*) == 4 ? 24 : 40, sizeof(ForStmt));
static_assert(8, sizeof(BreakStmt));
static_assert(8, sizeof(CompoundStmt));
static_assert(8, sizeof(ContinueStmt));
static_assert(8, sizeof(FallthroughStmt));
static_assert(8, sizeof(ReturnStmt));

static_assert(16, sizeof(Expr));
static_assert(16, sizeof(BooleanLiteral));
static_assert(16, sizeof(CharLiteral));
static_assert(32, sizeof(MemberExpr));
static_assert(16, sizeof(NilExpr));
static_assert(24, sizeof(IdentifierExpr));
static_assert(24, sizeof(ImplicitCastExpr));
static_assert(24, sizeof(InitListExpr));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(Expr));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(BooleanLiteral));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(CharLiteral));
static_assert(sizeof(void*) == 4 ? 20 : 32, sizeof(MemberExpr));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(NilExpr));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(IdentifierExpr));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(ImplicitCastExpr));
static_assert(sizeof(void*) == 4 ? 20 : 24, sizeof(InitListExpr));
static_assert(24, sizeof(IntegerLiteral));
static_assert(24, sizeof(ParenExpr));
static_assert(24, sizeof(StringLiteral));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(ParenExpr));
static_assert(sizeof(void*) == 4 ? 20 : 24, sizeof(StringLiteral));
static_assert(24, sizeof(TypeExpr));
static_assert(24, sizeof(UnaryOperator));
static_assert(32, sizeof(ArrayDesignatedInitExpr));
static_assert(32, sizeof(ArraySubscriptExpr));
static_assert(32, sizeof(BinaryOperator));
static_assert(32, sizeof(BitOffsetExpr));
static_assert(32, sizeof(CallExpr));
static_assert(40, sizeof(ExplicitCastExpr));
static_assert(32, sizeof(BuiltinExpr));
static_assert(40, sizeof(FieldDesignatedInitExpr));
static_assert(48, sizeof(ConditionalOperator));
static_assert(32, sizeof(NamedArgument));
static_assert(32, sizeof(AlternateExpr));

static_assert(8, sizeof(QualType));
static_assert(16, sizeof(Type));
static_assert(16, sizeof(BuiltinType));
static_assert(24, sizeof(EnumType));
static_assert(24, sizeof(FunctionType));
static_assert(24, sizeof(PointerType));
static_assert(24, sizeof(StructType));
static_assert(32, sizeof(ArrayType));

static_assert(16, sizeof(ArrayValue));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(UnaryOperator));
static_assert(sizeof(void*) == 4 ? 24 : 32, sizeof(ArrayDesignatedInitExpr));
static_assert(sizeof(void*) == 4 ? 20 : 32, sizeof(ArraySubscriptExpr));
static_assert(sizeof(void*) == 4 ? 20 : 32, sizeof(BinaryOperator));
static_assert(sizeof(void*) == 4 ? 20 : 32, sizeof(BitOffsetExpr));
static_assert(sizeof(void*) == 4 ? 24 : 32, sizeof(CallExpr));
static_assert(sizeof(void*) == 4 ? 32 : 40, sizeof(ExplicitCastExpr));
static_assert(sizeof(void*) == 4 ? 24 : 32, sizeof(BuiltinExpr));
static_assert(sizeof(void*) == 4 ? 24 : 40, sizeof(FieldDesignatedInitExpr));
static_assert(sizeof(void*) == 4 ? 28 : 48, sizeof(ConditionalOperator));
static_assert(sizeof(void*) == 4 ? 24 : 32, sizeof(NamedArgument));
static_assert(sizeof(void*) == 4 ? 20 : 32, sizeof(AlternateExpr));

static_assert(sizeof(void*) == 4 ? 4 : 8, sizeof(QualType));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(Type));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(BuiltinType));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(EnumType));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(FunctionType));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(PointerType));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(StructType));
static_assert(sizeof(void*) == 4 ? 20 : 32, sizeof(ArrayType));

static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(ArrayValue));
static_assert(8, sizeof(SwitchCase));
static_assert(24, sizeof(StaticAssert));
static_assert(sizeof(void*) == 4 ? 16 : 24, sizeof(StaticAssert));
static_assert(8, sizeof(TypeRef));

#endif
Expand Down
4 changes: 2 additions & 2 deletions ast/var_decl.c2
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ type BitFieldInfo struct {
BitFieldLayout layout;
// u16 pad
}
static_assert(16, sizeof(BitFieldInfo));
static_assert(sizeof(void*) == 4 ? 12 : 16, sizeof(BitFieldInfo));

type VarDeclInit struct {
Expr* expr;
SrcLoc loc;
// u32 pad
}
static_assert(16, sizeof(VarDeclInit));
static_assert(sizeof(void*) == 4 ? 8 : 16, sizeof(VarDeclInit));

public type VarDecl struct @(opaque) {
Decl base;
Expand Down
2 changes: 1 addition & 1 deletion ast_utils/attr.c2
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public type Attr struct {
AttrValueKind value_kind;
AttrValue value;
}
static_assert(32, sizeof(Attr));
static_assert(sizeof(void*) == 4 ? 24 : 32, sizeof(Attr));

// Note: only meant for printing (since not allocated in StringPool)
public fn const char* Attr.kind2name(const Attr* a) {
Expand Down
Loading
Loading