diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2d77a1c9f..58f4c8066 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,6 @@ jobs: - name: bootstrap + compile run: | . env.sh - make globals make all - name: run unit-tests @@ -35,24 +34,26 @@ jobs: . 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 diff --git a/Makefile b/Makefile index da45569a1..7cec450e2 100644 --- a/Makefile +++ b/Makefile @@ -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} @@ -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) @@ -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 @@ -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: diff --git a/analyser/module_analyser_call.c2 b/analyser/module_analyser_call.c2 index 44e841886..ec5917691 100644 --- a/analyser/module_analyser_call.c2 +++ b/analyser/module_analyser_call.c2 @@ -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; @@ -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; } } diff --git a/ast/ast.c2 b/ast/ast.c2 index 994c7abfc..8f63c45e8 100644 --- a/ast/ast.c2 +++ b/ast/ast.c2 @@ -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)); diff --git a/ast/builtin_type.c2 b/ast/builtin_type.c2 index 97318f381..3f8213fbb 100644 --- a/ast/builtin_type.c2 +++ b/ast/builtin_type.c2 @@ -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; diff --git a/ast/function_type.c2 b/ast/function_type.c2 index be2cd28f8..a5c2c18c4 100644 --- a/ast/function_type.c2 +++ b/ast/function_type.c2 @@ -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)); diff --git a/ast/member_expr.c2 b/ast/member_expr.c2 index 444c71827..c7dad8a00 100644 --- a/ast/member_expr.c2 +++ b/ast/member_expr.c2 @@ -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] diff --git a/ast/module.c2 b/ast/module.c2 index 75d144637..e1938c1dd 100644 --- a/ast/module.c2 +++ b/ast/module.c2 @@ -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) { diff --git a/ast/pointer_type.c2 b/ast/pointer_type.c2 index 601b64c5e..173871523 100644 --- a/ast/pointer_type.c2 +++ b/ast/pointer_type.c2 @@ -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)); diff --git a/ast/struct_type_decl.c2 b/ast/struct_type_decl.c2 index 3ebfef815..cc70447e5 100644 --- a/ast/struct_type_decl.c2 +++ b/ast/struct_type_decl.c2 @@ -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; diff --git a/ast/type_ref.c2 b/ast/type_ref.c2 index 1c7d10f8f..11dcbc692 100644 --- a/ast/type_ref.c2 +++ b/ast/type_ref.c2 @@ -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; diff --git a/ast/utils.c2 b/ast/utils.c2 index 56d8f0818..cfd7ce5b5 100644 --- a/ast/utils.c2 +++ b/ast/utils.c2 @@ -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 diff --git a/ast/var_decl.c2 b/ast/var_decl.c2 index cbf6ec2c2..88b3264e9 100644 --- a/ast/var_decl.c2 +++ b/ast/var_decl.c2 @@ -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; diff --git a/ast_utils/attr.c2 b/ast_utils/attr.c2 index 8b8ca3115..236057e8a 100644 --- a/ast_utils/attr.c2 +++ b/ast_utils/attr.c2 @@ -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) { diff --git a/ast_utils/context.c2 b/ast_utils/context.c2 index 8a482c954..f5b1e145e 100644 --- a/ast_utils/context.c2 +++ b/ast_utils/context.c2 @@ -129,14 +129,16 @@ fn void TailAllocator.report(const TailAllocator* c) { public type Context struct @(opaque) { TailAllocator allocator; u32 blk_size; - u32 wordsize; + u32 ptr_size; + u32 long_size; } -public fn Context* create(u32 blk_size, u32 wordsize) { +public fn Context* create(u32 blk_size, u32 ptr_size, u32 long_size) { Context* c = malloc(sizeof(Context)); c.allocator.init(blk_size); c.blk_size = blk_size; - c.wordsize = wordsize; + c.ptr_size = ptr_size; + c.long_size = long_size; return c; } @@ -152,7 +154,8 @@ public fn void Context.clear(Context* c) { } #endif -public fn u32 Context.getWordSize(Context* c) { return c.wordsize; } +public fn u32 Context.getPointerSize(Context* c) { return c.ptr_size; } +public fn u32 Context.getLongSize(Context* c) { return c.long_size; } public fn void* Context.alloc(Context* c, u32 len) { return c.allocator.alloc(len); diff --git a/ast_utils/string_buffer.c2 b/ast_utils/string_buffer.c2 index 387aaf60d..33a8f4462 100644 --- a/ast_utils/string_buffer.c2 +++ b/ast_utils/string_buffer.c2 @@ -33,7 +33,7 @@ public type Buf struct { u32 indent_step; } -static_assert(24, sizeof(Buf)); +static_assert(sizeof(void*) == 4 ? 20 : 24, sizeof(Buf)); public fn Buf* Buf.init(Buf* buf, char* data, u32 capacity, bool grow, bool use_colors, u32 indent_step) { assert(capacity); diff --git a/ast_utils/string_pool.c2 b/ast_utils/string_pool.c2 index 57784df4c..3de0654c2 100644 --- a/ast_utils/string_pool.c2 +++ b/ast_utils/string_pool.c2 @@ -62,7 +62,7 @@ public type Pool struct @(opaque) { u32 entry_capacity; HashEntry* entries; // contain hash table followed by collision lists } -static_assert(64, sizeof(Pool)); +static_assert(sizeof(void*) == 4 ? 56 : 64, sizeof(Pool)); public fn Pool* create(u32 data_capacity, u32 hash_size) { Pool* p = stdlib.calloc(1, sizeof(Pool)); diff --git a/bootstrap/Makefile b/bootstrap/Makefile index 4f223016f..b7adc1817 100644 --- a/bootstrap/Makefile +++ b/bootstrap/Makefile @@ -13,8 +13,9 @@ ARCH:=$(shell uname -m) ifeq (Linux,$(SYSTEM)) CC:=gcc LDFLAGS:=-ldl -ifdef CONFIG_32BIT +ifeq (y,$(CONFIG_M32)) BOOTSTRAP_FILE:=../output/bootstrap/bootstrap-linux-i686.c +ARCH:=i686 else BOOTSTRAP_FILE:=bootstrap.c endif @@ -43,7 +44,7 @@ LDFLAGS:= BOOTSTRAP_FILE:=../output/bootstrap/bootstrap-openbsd-amd64.c endif -ifeq (y,$(CONFIG_32BIT)) +ifeq (y,$(CONFIG_M32)) CFLAGS += -m32 LDFLAGS += -m32 endif @@ -58,7 +59,8 @@ all: ../output/bootstrap/bootstrap ../output/bootstrap/%.c: %.patch bootstrap.c @echo "---- patching bootstrap code for $(SYSTEM)-$(ARCH) ----" @mkdir -p ../output/bootstrap - @patch -s -o $@ bootstrap.c $< + @cp -f bootstrap.c $@ + @patch -s $@ $< ../output/bootstrap/globals: globals.c @echo "---- compiling header extractor ----" @@ -67,6 +69,7 @@ all: ../output/bootstrap/bootstrap globals: ../output/bootstrap/globals ../output/bootstrap/globals + rm ../output/bootstrap/globals clean: @rm -rf ../output/ diff --git a/bootstrap/bootstrap-linux-i686.patch b/bootstrap/bootstrap-linux-i686.patch new file mode 100644 index 000000000..9ceccb743 --- /dev/null +++ b/bootstrap/bootstrap-linux-i686.patch @@ -0,0 +1,7284 @@ +48,51c48,51 +< typedef signed long i64; +< typedef unsigned long u64; +< typedef signed long ssize_t; +< typedef unsigned long size_t; +--- +> typedef signed long long i64; +> typedef unsigned long long u64; +> typedef signed int ssize_t; +> typedef unsigned int size_t; +120c120 +< #define usize_max 0xFFFFFFFFFFFFFFFFUL +--- +> #define usize_max 0xFFFFFFFFU +133d132 +< #define c_errno_ENOENT 2 +234a234 +> int strtol(const char* nptr, char** endptr, int base); +260,262c260,262 +< u64 st_dev; +< u64 st_ino; +< u64 st_nlink; +--- +> u32 st_dev; +> u32 st_ino; +> u32 st_nlink; +266,276c266,276 +< u64 st_rdev; +< i64 st_size; +< i64 st_blksize; +< i64 st_blocks; +< i64 st_atime; +< i64 st_atime_nsec; +< i64 st_mtime; +< i64 st_mtime_nsec; +< i64 st_ctime; +< i64 st_ctime_nsec; +< i64 reserved[3]; +--- +> u32 st_rdev; +> int st_size; +> int st_blksize; +> int st_blocks; +> int st_atime; +> int st_atime_nsec; +> int st_mtime; +> int st_mtime_nsec; +> int st_ctime; +> int st_ctime_nsec; +> int reserved[3]; +291,292c291,292 +< typedef i64 time_t; +< typedef i64 suseconds_t; +--- +> typedef int time_t; +> typedef int suseconds_t; +309c309 +< #define sys_utsname_NAME_LEN 65 +--- +> #define _UTSNAME_LENGTH 65 +440a441 +> typedef struct ast_context_TailAllocator_ ast_context_TailAllocator; +450c451 +< struct ast_context_Context_ { +--- +> struct ast_context_TailAllocator_ { +459a461,467 +> struct ast_context_Context_ { +> ast_context_TailAllocator allocator; +> u32 blk_size; +> u32 ptr_size; +> u32 long_size; +> }; +> +462,464c470,474 +< static void ast_context_Context_init(ast_context_Context* c, u32 blk_size); +< static ast_context_Context* ast_context_create(u32 blk_size); +< static void ast_context_Context_freeBlocks(ast_context_Context* c); +--- +> static void ast_context_TailAllocator_init(ast_context_TailAllocator* c, u32 blk_size); +> static void ast_context_TailAllocator_freeBlocks(ast_context_TailAllocator* c); +> static void* ast_context_TailAllocator_alloc(ast_context_TailAllocator* c, u32 len); +> static void ast_context_TailAllocator_report(const ast_context_TailAllocator* c); +> static ast_context_Context* ast_context_create(u32 blk_size, u32 ptr_size, u32 long_size); +465a476,477 +> static u32 ast_context_Context_getPointerSize(ast_context_Context* c); +> static u32 ast_context_Context_getLongSize(ast_context_Context* c); +467c479 +< static void ast_context_Context_report(const ast_context_Context* c); +--- +> static void ast_context_Context_report(ast_context_Context* c); +471c483 +< ast_context_Block* b = malloc(16 + blk_size); +--- +> ast_context_Block* b = malloc(12 + blk_size); +485c497 +< static void ast_context_Context_init(ast_context_Context* c, u32 blk_size) +--- +> static void ast_context_TailAllocator_init(ast_context_TailAllocator* c, u32 blk_size) +489c501 +< c->blk_size = blk_size >= 1024 ? blk_size - 16 : blk_size; +--- +> c->blk_size = blk_size >= 1024 ? blk_size - 12 : blk_size; +496,503c508 +< static ast_context_Context* ast_context_create(u32 blk_size) +< { +< ast_context_Context* c = malloc(40); +< ast_context_Context_init(c, blk_size); +< return c; +< } +< +< static void ast_context_Context_freeBlocks(ast_context_Context* c) +--- +> static void ast_context_TailAllocator_freeBlocks(ast_context_TailAllocator* c) +510,516c515 +< static void ast_context_Context_free(ast_context_Context* c) +< { +< ast_context_Context_freeBlocks(c); +< free(c); +< } +< +< static void* ast_context_Context_alloc(ast_context_Context* c, u32 len) +--- +> static void* ast_context_TailAllocator_alloc(ast_context_TailAllocator* c, u32 len) +521c520 +< if (!c->blk_size) c->blk_size = 16384 - 16; +--- +> if (!c->blk_size) c->blk_size = 16384 - 12; +540c539 +< static void ast_context_Context_report(const ast_context_Context* c) +--- +> static void ast_context_TailAllocator_report(const ast_context_TailAllocator* c) +557a557,592 +> static ast_context_Context* ast_context_create(u32 blk_size, u32 ptr_size, u32 long_size) +> { +> ast_context_Context* c = malloc(40); +> ast_context_TailAllocator_init(&c->allocator, blk_size); +> c->blk_size = blk_size; +> c->ptr_size = ptr_size; +> c->long_size = long_size; +> return c; +> } +> +> static void ast_context_Context_free(ast_context_Context* c) +> { +> ast_context_TailAllocator_freeBlocks(&c->allocator); +> free(c); +> } +> +> static u32 ast_context_Context_getPointerSize(ast_context_Context* c) +> { +> return c->ptr_size; +> } +> +> static u32 ast_context_Context_getLongSize(ast_context_Context* c) +> { +> return c->long_size; +> } +> +> static void* ast_context_Context_alloc(ast_context_Context* c, u32 len) +> { +> return ast_context_TailAllocator_alloc(&c->allocator, len); +> } +> +> static void ast_context_Context_report(ast_context_Context* c) +> { +> ast_context_TailAllocator_report(&c->allocator); +> } +> +645c680 +< string_buffer_Buf* buf = malloc(24); +--- +> string_buffer_Buf* buf = malloc(20); +826a862 +> if (sep) string_buffer_Buf_add1(buf, sep); +855c891 +< if (sep && sep != c) goto normal; +--- +> if (sep && c != sep) goto normal; +883a920 +> if (sep) string_buffer_Buf_add1(buf, sep); +893a931 +> typedef struct string_pool_Block_ string_pool_Block; +897,899c935,937 +< struct string_pool_Pool_ { +< u32 data_size; +< u32 data_capacity; +--- +> struct string_pool_Block_ { +> u32 size; +> u32 capacity; +900a939,944 +> }; +> +> struct string_pool_Pool_ { +> u32 blocks_count; +> u32 blocks_capacity; +> string_pool_Block* blocks; +902a947,950 +> u32 num_strs; +> u32 data_size; +> u32 data_capacity; +> u32 pad; +913a962 +> #define string_pool_BLOCK_SIZE 16384 +918c967 +< static u32 string_pool_hash(const char* text, size_t len); +--- +> static u32 string_pool_Pool_hash(const char* text, size_t len); +920c969 +< static bool string_pool_same_string(const char* left, const char* right, size_t rlen); +--- +> static bool string_pool_Pool_same_string(const char* left, const char* right, size_t rlen); +923d971 +< static void string_pool_Pool_resize_data(string_pool_Pool* p, u32 capacity); +929,931c977,986 +< string_pool_Pool* p = calloc(1, 48); +< string_pool_Pool_resize_data(p, data_capacity); +< p->data[0] = 0; +--- +> string_pool_Pool* p = calloc(1, 56); +> data_capacity = string_pool_BLOCK_SIZE; +> string_pool_Block* bp = malloc(4 * 12); +> p->blocks = bp; +> p->blocks_capacity = 4; +> p->blocks_count = 1; +> bp->data = malloc(data_capacity); +> bp->data[0] = 0; +> bp->size = string_pool_DATA_ALIGN; +> bp->capacity = data_capacity; +933,940c988,989 +< if (hash_size & (hash_size - 1)) { +< hash_size |= hash_size >> 16; +< hash_size |= hash_size >> 8; +< hash_size |= hash_size >> 4; +< hash_size |= hash_size >> 2; +< hash_size |= hash_size >> 1; +< hash_size += 1; +< } +--- +> p->data_capacity = data_capacity; +> while (hash_size & (hash_size - 1)) hash_size = (hash_size | (hash_size - 1)) + 1; +952c1001,1002 +< free(p->data); +--- +> while (p->blocks_count) free(p->blocks[--p->blocks_count].data); +> free(p->blocks); +956c1006 +< static u32 string_pool_hash(const char* text, size_t len) +--- +> static u32 string_pool_Pool_hash(const char* text, size_t len) +968c1018 +< return p->data + idx; +--- +> return p->blocks[idx / string_pool_BLOCK_SIZE].data + idx % string_pool_BLOCK_SIZE; +971c1021 +< static bool string_pool_same_string(const char* left, const char* right, size_t rlen) +--- +> static bool string_pool_Pool_same_string(const char* left, const char* right, size_t rlen) +982a1033,1034 +> string_pool_HashEntry hh; +> string_pool_HashEntry* hp = &hh; +984,985c1036,1037 +< size_t i = string_pool_hash(text, len) & p->hash_mask; +< string_pool_HashEntry v = p->entries[i]; +--- +> size_t h = string_pool_Pool_hash(text, len) & p->hash_mask; +> string_pool_HashEntry v = p->entries[h]; +990,991c1042 +< const char* word = p->data + index; +< if (string_pool_same_string(word, text, len)) return index; +--- +> if (string_pool_Pool_same_string(string_pool_Pool_idx2str(p, index), text, len)) return index; +994,995c1045,1046 +< i = next; +< v = p->entries[i]; +--- +> h = next; +> v = p->entries[h]; +1001c1052 +< p->entries[i] = v | (next << string_pool_NEXT_SHIFT); +--- +> p->entries[h] = v | (next << string_pool_NEXT_SHIFT); +1003c1054 +< i = next; +--- +> h = next; +1005c1056 +< p->entries[i] = (p->data_size >> string_pool_INDEX_SHIFT); +--- +> hp = &p->entries[h]; +1008,1018c1059,1082 +< while (p->data_size + len + 1 > p->data_capacity) { +< if (text >= p->data && text < p->data + p->data_size) { +< ssize_t offset = text - p->data; +< string_pool_Pool_resize_data(p, p->data_capacity * 2); +< text = p->data + offset; +< } else { +< string_pool_Pool_resize_data(p, p->data_capacity * 2); +< } +< } +< u32 idx = p->data_size; +< char* dest = p->data + idx; +--- +> p->num_strs++; +> p->data_size += len + 1; +> u32 b = p->blocks_count - 1; +> string_pool_Block* bp = &p->blocks[b]; +> if (bp->size + len < bp->capacity) goto has_bp; +> while (b-- > 0) { +> bp--; +> if (bp->size + len < bp->capacity) goto has_bp; +> } +> if (p->blocks_count == p->blocks_capacity) { +> p->blocks_capacity *= 2; +> p->blocks = realloc(p->blocks, p->blocks_capacity * 12); +> } +> b = p->blocks_count++; +> bp = &p->blocks[b]; +> u32 block_size = string_pool_BLOCK_SIZE; +> if (len >= string_pool_BLOCK_SIZE) block_size = (u32)len / string_pool_DATA_ALIGN * string_pool_DATA_ALIGN + string_pool_DATA_ALIGN; +> p->data_capacity += block_size; +> bp->data = malloc(block_size); +> bp->size = 0; +> bp->capacity = block_size; +> has_bp:; +> u32 idx = b * string_pool_BLOCK_SIZE + bp->size; +> char* dest = bp->data + bp->size; +1021c1085,1086 +< p->data_size += len / string_pool_DATA_ALIGN * string_pool_DATA_ALIGN + string_pool_DATA_ALIGN; +--- +> bp->size += (u32)len / string_pool_DATA_ALIGN * string_pool_DATA_ALIGN + string_pool_DATA_ALIGN; +> *hp = (idx >> string_pool_INDEX_SHIFT); +1030,1040d1094 +< static void string_pool_Pool_resize_data(string_pool_Pool* p, u32 capacity) +< { +< p->data_capacity = capacity; +< char* data2 = malloc(capacity); +< if (p->data_size) { +< memcpy(data2, p->data, p->data_size); +< free(p->data); +< } +< p->data = data2; +< } +< +1043,1047c1097 +< string_pool_HashEntry* entries = malloc(capacity * 4); +< if (p->entries) { +< memcpy(entries, p->entries, p->entry_size * 4); +< free(p->entries); +< } +--- +> p->entries = realloc(p->entries, capacity * 4); +1049d1098 +< p->entries = entries; +1069,1072c1118,1119 +< if (num) { +< if (num > max) max = num; +< if (num < min) min = num; +< } +--- +> if (num > max) max = num; +> if (num < min) min = num; +1075c1122 +< printf("%s: count %u, adds %u, data %u/%u\n", name, p->hash_count, p->num_adds, p->data_size, p->data_capacity); +--- +> printf("%s: count %u/%u, adds %u/%u, data %u/%u\n", name, p->hash_count, p->num_strs, p->num_adds, p->total_size, p->data_size, p->data_capacity); +2024c2071 +< snprintf(out + v->negative, out_size - 1, "%lu", v->uvalue); +--- +> snprintf(out + v->negative, out_size - 1, "%llu", v->uvalue); +2082,2086c2129,2133 +< static const char* yaml_node_names[4] = { +< [yaml_NodeKind_Unknown] = "UNK", +< [yaml_NodeKind_Scalar] = "SCA", +< [yaml_NodeKind_Map] = "MAP", +< [yaml_NodeKind_Sequence] = "SEQ" +--- +> static const char* const yaml_NodeKind__name[4] = { "UNK", "SCA", "MAP", "SEQ" }; +> static const char* const yaml_TokenKind__name[13] = { +> "none", "scalar", "'scalar'", "\"scalar\"", ":", +> "-", "indent", "dedent", "---", "...", +> "%", "eof", "error" +2160,2174d2206 +< static const char* yaml_token_names[13] = { +< [yaml_TokenKind_None] = "none", +< [yaml_TokenKind_Plain_Scalar] = "scalar", +< [yaml_TokenKind_Single_Quoted_Scalar] = "'scalar'", +< [yaml_TokenKind_Double_Quoted_Scalar] = "\"scalar\"", +< [yaml_TokenKind_Colon] = ":", +< [yaml_TokenKind_Dash] = "-", +< [yaml_TokenKind_Indent] = "indent", +< [yaml_TokenKind_Dedent] = "dedent", +< [yaml_TokenKind_Doc_Start] = "---", +< [yaml_TokenKind_Doc_End] = "...", +< [yaml_TokenKind_Directive] = "%", +< [yaml_TokenKind_Eof] = "eof", +< [yaml_TokenKind_Error] = "error" +< }; +2419c2451 +< return yaml_token_names[tok->kind]; +--- +> return yaml_TokenKind__name[tok->kind]; +2424c2456 +< memset(t, 0, 80); +--- +> memset(t, 0, 48); +2633c2665 +< yaml_Parser* p = calloc(1, 808); +--- +> yaml_Parser* p = calloc(1, 656); +2686c2718 +< yaml_Parser_error(p, "expected '%s', got '%s'", yaml_token_names[kind], yaml_Token_str(&p->token)); +--- +> yaml_Parser_error(p, "expected '%s', got '%s'", yaml_TokenKind__name[kind], yaml_Token_str(&p->token)); +2922c2954 +< yaml_Parser_error(p, "invalid scalar after %s", yaml_node_names[parent->kind]); +--- +> yaml_Parser_error(p, "invalid scalar after %s", yaml_NodeKind__name[parent->kind]); +2928a2961 +> typedef struct console_Config_ console_Config; +2930,2932c2963,2970 +< static bool console_use_color = false; +< static bool console_show_debug = false; +< static bool console_show_timing = false; +--- +> struct console_Config_ { +> bool use_color; +> bool quiet_mode; +> bool show_debug; +> bool show_timing; +> }; +> +> static console_Config console_config = { }; +2934c2972,2973 +< static void console_init(void); +--- +> static void console_init(const console_Config* c); +> static void console_setQuiet(bool enable); +2936a2976,2977 +> static console_Config* console_getConfig(void); +> static void console_setConfig(const console_Config* c); +2949c2990,2999 +< static void console_init(void) +--- +> static void console_init(const console_Config* c) +> { +> if (c) { +> console_setConfig(c); +> } else { +> console_config.use_color = color_useColor(); +> } +> } +> +> static void console_setQuiet(bool enable) +2951c3001 +< console_use_color = color_useColor(); +--- +> console_config.quiet_mode = enable; +2956c3006 +< console_show_debug = enable; +--- +> console_config.show_debug = enable; +2961c3011,3021 +< console_show_timing = enable; +--- +> console_config.show_timing = enable; +> } +> +> static console_Config* console_getConfig(void) +> { +> return &console_config; +> } +> +> static void console_setConfig(const console_Config* c) +> { +> console_config = *c; +2967c3027 +< if (!console_show_debug) return; +--- +> if (!console_config.show_debug) return; +2973c3033 +< if (console_use_color) { +--- +> if (console_config.use_color) { +2982a3043 +> if (console_config.quiet_mode) return; +2999c3060 +< if (console_use_color) { +--- +> if (console_config.use_color) { +3014c3075 +< if (console_use_color) { +--- +> if (console_config.use_color) { +3029c3090 +< if (console_use_color) { +--- +> if (console_config.use_color) { +3038,3040c3099,3101 +< if (!console_show_timing) return; +< if (console_use_color) { +< printf("%s%s took %lu usec%s\n", color_Color_str(color_Blue), item, duration, color_Color_str(color_Normal)); +--- +> if (!console_config.show_timing) return; +> if (console_config.use_color) { +> printf("%s%s took %llu usec%s\n", color_Color_str(color_Blue), item, duration, color_Color_str(color_Normal)); +3042c3103 +< printf("%s took %lu usec\n", item, duration); +--- +> printf("%s took %llu usec\n", item, duration); +3756c3817 +< source_mgr_SourceMgr* sm = calloc(1, 48); +--- +> source_mgr_SourceMgr* sm = calloc(1, 32); +3759c3820 +< sm->files = malloc(32 * sm->max_files); +--- +> sm->files = malloc(24 * sm->max_files); +3796,3797c3857,3858 +< source_mgr_File* files2 = malloc(32 * sm->max_files); +< memcpy(files2, sm->files, sm->num_files * 32); +--- +> source_mgr_File* files2 = malloc(24 * sm->max_files); +> memcpy(files2, sm->files, sm->num_files * 24); +3841c3902 +< memset(f, 0, 32); +--- +> memset(f, 0, 24); +3931c3992 +< u32 total_size = 48 + sm->max_files * 32 + sm->index_capacity * 2; +--- +> u32 total_size = 32 + sm->max_files * 24 + sm->index_capacity * 2; +3972d4032 +< static bool string_list_List_contains(const string_list_List* l, const char* name); +3981c4041 +< memset(l, 0, 24); +--- +> memset(l, 0, 16); +4031,4038d4090 +< static bool string_list_List_contains(const string_list_List* l, const char* name) +< { +< for (u32 i = 0; i < l->count; i++) { +< if (strcmp(string_pool_Pool_idx2str(l->pool, l->indexes[i]), name) == 0) return true; +< } +< return false; +< } +< +4067a4120,4227 +> // --- module string_map --- +> typedef struct string_map_Map_ string_map_Map; +> +> struct string_map_Map_ { +> string_pool_Pool* pool; +> u32* names; +> u32* values; +> u32 count; +> u32 capacity; +> }; +> +> static void string_map_Map_init(string_map_Map* m, string_pool_Pool* pool); +> static void string_map_Map_free(string_map_Map* m); +> static void string_map_Map_resize(string_map_Map* m, u32 capacity); +> static void string_map_Map_add(string_map_Map* m, u32 name_idx, u32 value_idx); +> static u32 string_map_Map_del(string_map_Map* m, u32 name_idx); +> static void string_map_Map_addNameValue(string_map_Map* m, u32 idx, const char* def); +> static bool string_map_Map_contains(const string_map_Map* m, const char* name, u32* indexp); +> static const char* string_map_Map_getValue(const string_map_Map* m, u32 i); +> +> static void string_map_Map_init(string_map_Map* m, string_pool_Pool* pool) +> { +> memset(m, 0, 20); +> m->pool = pool; +> string_map_Map_resize(m, 16); +> } +> +> static void string_map_Map_free(string_map_Map* m) +> { +> free(m->names); +> free(m->values); +> m->names = NULL; +> m->values = NULL; +> m->count = 0; +> m->capacity = 0; +> } +> +> static void string_map_Map_resize(string_map_Map* m, u32 capacity) +> { +> m->capacity = capacity; +> u32* names2 = malloc(capacity * 4); +> u32* values2 = malloc(capacity * 4); +> if (m->count) { +> memcpy(names2, m->names, m->count * 4); +> memcpy(values2, m->values, m->count * 4); +> free(m->names); +> free(m->values); +> } +> m->names = names2; +> m->values = values2; +> } +> +> static void string_map_Map_add(string_map_Map* m, u32 name_idx, u32 value_idx) +> { +> if (m->count == m->capacity) string_map_Map_resize(m, m->capacity * 2); +> m->names[m->count] = name_idx; +> m->values[m->count] = value_idx; +> m->count++; +> } +> +> static u32 string_map_Map_del(string_map_Map* m, u32 name_idx) +> { +> u32 j = 0; +> u32 count = m->count; +> for (u32 i = 0; i < count; i++) { +> if (m->names[i] != name_idx) { +> m->names[j] = m->names[i]; +> m->values[j] = m->values[i]; +> j++; +> } +> } +> m->count = j; +> return count - j; +> } +> +> static void string_map_Map_addNameValue(string_map_Map* m, u32 idx, const char* def) +> { +> const char* str = string_pool_Pool_idx2str(m->pool, idx); +> u32 len; +> const char* value = def; +> for (len = 0; str[len]; len++) { +> if (str[len] == '=') { +> u32 new_idx = string_pool_Pool_add(m->pool, str, len, true); +> value = string_pool_Pool_idx2str(m->pool, idx) + len + 1; +> idx = new_idx; +> break; +> } +> } +> string_map_Map_add(m, idx, string_pool_Pool_addStr(m->pool, value, true)); +> } +> +> static bool string_map_Map_contains(const string_map_Map* m, const char* name, u32* indexp) +> { +> for (u32 i = 0; i < m->count; i++) { +> if (!strcmp(string_pool_Pool_idx2str(m->pool, m->names[i]), name)) { +> if (indexp) *indexp = i; +> return true; +> } +> } +> return false; +> } +> +> static const char* string_map_Map_getValue(const string_map_Map* m, u32 i) +> { +> return string_pool_Pool_idx2str(m->pool, m->values[i]); +> } +> +> +4194a4355,4356 +> static bool utils_checkFile(const char* filename); +> static u32 utils_changeToProjectDir(utils_PathInfo* info, const char* other_dir); +4212a4375,4404 +> static bool utils_checkFile(const char* filename) +> { +> struct stat buf; +> int error = stat(filename, &buf); +> if (error) return false; +> if ((buf.st_mode & sys_stat_S_IFMT) != sys_stat_S_IFREG) return false; +> return true; +> } +> +> static u32 utils_changeToProjectDir(utils_PathInfo* info, const char* other_dir) +> { +> char* path = getcwd(info->orig2root, 512 - 1); +> if (path == NULL) { +> perror("getcwd"); +> return 2; +> } +> size_t len = strlen(path); +> info->orig2root[len] = '/'; +> info->orig2root[len + 1] = 0; +> strcpy(info->root2orig, other_dir); +> len = strlen(other_dir); +> if (other_dir[len - 1] != '/') { +> info->root2orig[len] = '/'; +> info->root2orig[len + 1] = 0; +> } +> if (chdir(other_dir)) return 2; +> if (!utils_checkFile(constants_recipe_name)) return 3; +> return 0; +> } +> +4225c4417 +< char* path = getcwd(buffer, 512); +--- +> char* path = getcwd(buffer, 512 - 1); +4230,4246c4422,4431 +< if (base_path[0] == 0) strcpy(base_path, path); +< struct stat buf; +< if (stat(constants_recipe_name, &buf)) { +< if (path[0] == '/' && path[1] == '\0') return false; +< if ((*__errno_location()) != c_errno_ENOENT) { +< perror("stat"); +< return false; +< } +< } else { +< if ((buf.st_mode & sys_stat_S_IFMT) == sys_stat_S_IFREG) { +< char* path_prefix = base_path + strlen(path); +< if (*path_prefix == '/') path_prefix++; +< if (info) { +< strcpy(info->orig2root, path_prefix); +< strcpy(info->root2orig, rel_path); +< } +< return true; +--- +> if (base_path[0] == 0) { +> strcpy(base_path, path); +> strcat(base_path, "/"); +> } +> if (utils_checkFile(constants_recipe_name)) { +> char* path_prefix = base_path + strlen(path); +> if (*path_prefix == '/') path_prefix++; +> if (info) { +> strcpy(info->orig2root, path_prefix); +> strcpy(info->root2orig, rel_path); +4247a4433 +> return true; +4248a4435 +> if (path[0] == '/' && path[1] == '\0') return false; +4259,4261c4446 +< struct stat buf; +< int error = stat(constants_buildfile_name, &buf); +< if (error) return NULL; +--- +> if (!utils_checkFile(constants_buildfile_name)) return NULL; +4514,4515c4699,4700 +< build_file_Info* result = malloc(112); +< memcpy(result, &info, 112); +--- +> build_file_Info* result = malloc(84); +> memcpy(result, &info, 84); +4653c4838,4839 +< u32 intWidth; +--- +> u32 ptrWidth; +> u32 longWidth; +4657c4843,4852 +< static const char* target_info_system_names[6] = { +--- +> static const char* const target_info_Arch__name[8] = { +> "unknown", "i686", "arm", "x86_64", "amd64", "arm64", "riscv32", "riscv64" +> }; +> static target_info_Arch target_info_Arch__m32_version[8] = { +> target_info_Arch_Unknown, target_info_Arch_I686, +> target_info_Arch_Arm, target_info_Arch_I686, +> target_info_Arch_I686, target_info_Arch_Arm, +> target_info_Arch_Riscv_32, target_info_Arch_Riscv_32 +> }; +> static const char* const target_info_System__name[6] = { +4660,4661c4855,4857 +< static const char* target_info_arch_names[8] = { +< "unknown", "i686", "arm", "x86_64", "amd64", "arm64", "riscv32", "riscv64" +--- +> static const char* const target_info_Vendor__name[2] = { "unknown", "apple" }; +> static const char* const target_info_Abi__name[7] = { +> "unknown", "gnu", "gnueabi", "macho", "win32", "rv32", "bsd" +4663,4664d4858 +< static const char* target_info_vendor_names[2] = { "unknown", "apple" }; +< static const char* target_info_abi_names[7] = { "unknown", "gnu", "gnueabi", "macho", "win32", "rv32", "bsd" }; +4666c4860 +< static target_info_Arch target_info_str2arch(const char* name); +--- +> static target_info_Arch target_info_str2arch(const char* name, bool m32); +4677c4871 +< if (strcasecmp(target_info_system_names[i], name) == 0) return i; +--- +> if (strcasecmp(target_info_System__name[i], name) == 0) return i; +4682c4876 +< static target_info_Arch target_info_str2arch(const char* name) +--- +> static target_info_Arch target_info_str2arch(const char* name, bool m32) +4684,4685c4878,4879 +< for (target_info_Arch i = target_info_Arch_Unknown; i <= target_info_Arch_Riscv_64; i++) { +< if (strcasecmp(target_info_arch_names[i], name) == 0) return i; +--- +> for (target_info_Arch a = target_info_Arch_Unknown; a <= target_info_Arch_Riscv_64; a++) { +> if (strcasecmp(target_info_Arch__name[a], name) == 0) return m32 ? target_info_Arch__m32_version[a] : a; +4693c4887 +< if (strcasecmp(target_info_vendor_names[i], name) == 0) return i; +--- +> if (strcasecmp(target_info_Vendor__name[i], name) == 0) return i; +4701c4895 +< if (strcasecmp(target_info_abi_names[i], name) == 0) return i; +--- +> if (strcasecmp(target_info_Abi__name[i], name) == 0) return i; +4710c4904,4905 +< info->intWidth = 64; +--- +> info->ptrWidth = 64; +> info->longWidth = 64; +4714c4909,4910 +< info->intWidth = 32; +--- +> info->ptrWidth = 32; +> info->longWidth = 32; +4719c4915,4916 +< info->intWidth = 64; +--- +> info->ptrWidth = 64; +> info->longWidth = 64; +4722c4919,4920 +< info->intWidth = 32; +--- +> info->ptrWidth = 32; +> info->longWidth = 32; +4725c4923,4924 +< info->intWidth = 64; +--- +> info->ptrWidth = 64; +> info->longWidth = 64; +4728c4927 +< snprintf(info->triple, 80, "%s-%s-%s-%s", target_info_arch_names[info->arch], target_info_vendor_names[info->vendor], target_info_system_names[info->sys], target_info_abi_names[info->abi]); +--- +> snprintf(info->triple, 80, "%s-%s-%s-%s", target_info_Arch__name[info->arch], target_info_Vendor__name[info->vendor], target_info_System__name[info->sys], target_info_Abi__name[info->abi]); +4738c4937 +< return target_info_system_names[info->sys]; +--- +> return target_info_System__name[info->sys]; +4743c4942 +< return target_info_arch_names[info->arch]; +--- +> return target_info_Arch__name[info->arch]; +4747,4750d4945 +< // --- module value_maplist --- +< +< +< +4842d5036 +< token_Kind_KW_cast, +4848,4849d5041 +< token_Kind_KW_enum_max, +< token_Kind_KW_enum_min, +4916,5051c5108,5135 +< static const char* token_token_names[135] = { +< [token_Kind_None] = "none", +< [token_Kind_Identifier] = "identifier", +< [token_Kind_IntegerLiteral] = "integer", +< [token_Kind_FloatLiteral] = "float", +< [token_Kind_CharLiteral] = "character", +< [token_Kind_StringLiteral] = "string", +< [token_Kind_LParen] = "(", +< [token_Kind_RParen] = ")", +< [token_Kind_LSquare] = "[", +< [token_Kind_RSquare] = "]", +< [token_Kind_LBrace] = "{", +< [token_Kind_RBrace] = "}", +< [token_Kind_Exclaim] = "!", +< [token_Kind_ExclaimEqual] = "!=", +< [token_Kind_Star] = "*", +< [token_Kind_StarEqual] = "*=", +< [token_Kind_Amp] = "&", +< [token_Kind_AmpAmp] = "&&", +< [token_Kind_AmpEqual] = "&=", +< [token_Kind_Pipe] = "|", +< [token_Kind_PipePipe] = "||", +< [token_Kind_PipeEqual] = "|=", +< [token_Kind_Equal] = "=", +< [token_Kind_EqualEqual] = "==", +< [token_Kind_Semicolon] = ";", +< [token_Kind_Colon] = ":", +< [token_Kind_At] = "@", +< [token_Kind_Caret] = "^", +< [token_Kind_CaretEqual] = "^=", +< [token_Kind_Question] = "?", +< [token_Kind_Dot] = ".", +< [token_Kind_Ellipsis] = "...", +< [token_Kind_Comma] = ",", +< [token_Kind_Plus] = "+", +< [token_Kind_PlusPlus] = "++", +< [token_Kind_PlusEqual] = "+=", +< [token_Kind_Minus] = "-", +< [token_Kind_MinusMinus] = "--", +< [token_Kind_MinusEqual] = "-=", +< [token_Kind_Tilde] = "~", +< [token_Kind_Slash] = "/", +< [token_Kind_SlashEqual] = "/=", +< [token_Kind_Percent] = "%", +< [token_Kind_PercentEqual] = "%=", +< [token_Kind_Less] = "<", +< [token_Kind_LessLess] = "<<", +< [token_Kind_LessEqual] = "<=", +< [token_Kind_LessLessEqual] = "<<=", +< [token_Kind_Greater] = ">", +< [token_Kind_GreaterGreater] = ">>", +< [token_Kind_GreaterEqual] = ">=", +< [token_Kind_GreaterGreaterEqual] = ">>=", +< [token_Kind_KW_bool] = "bool", +< [token_Kind_KW_char] = "char", +< [token_Kind_KW_i8] = "i8", +< [token_Kind_KW_i16] = "i16", +< [token_Kind_KW_i32] = "i32", +< [token_Kind_KW_i64] = "i64", +< [token_Kind_KW_u8] = "u8", +< [token_Kind_KW_u16] = "u16", +< [token_Kind_KW_u32] = "u32", +< [token_Kind_KW_u64] = "u64", +< [token_Kind_KW_reg8] = "reg8", +< [token_Kind_KW_reg16] = "reg16", +< [token_Kind_KW_reg32] = "reg32", +< [token_Kind_KW_reg64] = "reg64", +< [token_Kind_KW_isize] = "isize", +< [token_Kind_KW_usize] = "usize", +< [token_Kind_KW_f32] = "f32", +< [token_Kind_KW_f64] = "f64", +< [token_Kind_KW_void] = "void", +< [token_Kind_KW_int] = "int", +< [token_Kind_KW_ssize_t] = "ssize_t", +< [token_Kind_KW_size_t] = "size_t", +< [token_Kind_KW_float] = "float", +< [token_Kind_KW_double] = "double", +< [token_Kind_KW_short] = "short", +< [token_Kind_KW_long] = "long", +< [token_Kind_KW_signed] = "signed", +< [token_Kind_KW_unsigned] = "unsigned", +< [token_Kind_KW_typedef] = "typedef", +< [token_Kind_KW_as] = "as", +< [token_Kind_KW_asm] = "asm", +< [token_Kind_KW_assert] = "assert", +< [token_Kind_KW_break] = "break", +< [token_Kind_KW_case] = "case", +< [token_Kind_KW_cast] = "cast", +< [token_Kind_KW_const] = "const", +< [token_Kind_KW_continue] = "continue", +< [token_Kind_KW_default] = "default", +< [token_Kind_KW_elemsof] = "elemsof", +< [token_Kind_KW_else] = "else", +< [token_Kind_KW_enum_max] = "enum_max", +< [token_Kind_KW_enum_min] = "enum_min", +< [token_Kind_KW_enum] = "enum", +< [token_Kind_KW_extern] = "extern", +< [token_Kind_KW_fallthrough] = "fallthrough", +< [token_Kind_KW_false] = "false", +< [token_Kind_KW_fn] = "fn", +< [token_Kind_KW_for] = "for", +< [token_Kind_KW_goto] = "goto", +< [token_Kind_KW_if] = "if", +< [token_Kind_KW_import] = "import", +< [token_Kind_KW_local] = "local", +< [token_Kind_KW_module] = "module", +< [token_Kind_KW_nil] = "nil", +< [token_Kind_KW_offsetof] = "offsetof", +< [token_Kind_KW_public] = "public", +< [token_Kind_KW_return] = "return", +< [token_Kind_KW_sizeof] = "sizeof", +< [token_Kind_KW_static] = "static", +< [token_Kind_KW_static_assert] = "static_assert", +< [token_Kind_KW_struct] = "struct", +< [token_Kind_KW_switch] = "switch", +< [token_Kind_KW_template] = "template", +< [token_Kind_KW_tlocal] = "tlocal", +< [token_Kind_KW_to_container] = "to_container", +< [token_Kind_KW_true] = "true", +< [token_Kind_KW_type] = "type", +< [token_Kind_KW_union] = "union", +< [token_Kind_KW_volatile] = "volatile", +< [token_Kind_KW_while] = "while", +< [token_Kind_Feat_if] = "#if", +< [token_Kind_Feat_ifdef] = "#ifdef", +< [token_Kind_Feat_ifndef] = "#ifndef", +< [token_Kind_Feat_elif] = "#elif", +< [token_Kind_Feat_else] = "#else", +< [token_Kind_Feat_endif] = "#endif", +< [token_Kind_Feat_error] = "#error", +< [token_Kind_Feat_warning] = "#warning", +< [token_Kind_Invalid] = "invalid", +< [token_Kind_LineComment] = "l-comment", +< [token_Kind_BlockComment] = "b-comment", +< [token_Kind_Eof] = "eof", +< [token_Kind_Error] = "error" +--- +> static const char* const token_Kind__name[132] = { +> "none", "identifier", "integer", "float", "character", +> "string", "(", ")", "[", "]", +> "{", "}", "!", "!=", "*", +> "*=", "&", "&&", "&=", "|", +> "||", "|=", "=", "==", ";", +> ":", "@", "^", "^=", "?", +> ".", "...", ",", "+", "++", +> "+=", "-", "--", "-=", "~", +> "/", "/=", "%", "%=", "<", +> "<<", "<=", "<<=", ">", ">>", +> ">=", ">>=", "bool", "char", "i8", +> "i16", "i32", "i64", "u8", "u16", +> "u32", "u64", "reg8", "reg16", "reg32", +> "reg64", "isize", "usize", "f32", "f64", +> "void", "int", "ssize_t", "size_t", "float", +> "double", "short", "long", "signed", "unsigned", +> "typedef", "as", "asm", "assert", "break", +> "case", "const", "continue", "default", "elemsof", +> "else", "enum", "extern", "fallthrough", "false", +> "fn", "for", "goto", "if", "import", +> "local", "module", "nil", "offsetof", "public", +> "return", "sizeof", "static", "static_assert", "struct", +> "switch", "template", "tlocal", "to_container", "true", +> "type", "union", "volatile", "while", "#if", +> "#ifdef", "#ifndef", "#elif", "#else", "#endif", +> "#error", "#warning", "invalid", "l-comment", "b-comment", +> "eof", "error" +5057d5140 +< static const char* token_Kind_str(token_Kind k); +5081,5085d5163 +< static const char* token_Kind_str(token_Kind k) +< { +< return token_token_names[k]; +< } +< +5216c5294 +< size_t cache[256]; +--- +> size_t cache[128]; +5580c5658 +< if (cp[pos] == '[') pos++; +--- +> if (cp[pos] == ']') pos++; +5730c5808 +< static const char* attr_attrKind_names[24] = { +--- +> static const char* const attr_AttrKind__name[24] = { +5737,5761c5815,5820 +< static const attr_AttrReq attr_Required_arg[24] = { +< [attr_AttrKind_Unknown] = attr_AttrReq_NoArg, +< [attr_AttrKind_Export] = attr_AttrReq_NoArg, +< [attr_AttrKind_Packed] = attr_AttrReq_NoArg, +< [attr_AttrKind_Unused] = attr_AttrReq_NoArg, +< [attr_AttrKind_UnusedParams] = attr_AttrReq_NoArg, +< [attr_AttrKind_Section] = attr_AttrReq_String, +< [attr_AttrKind_NoReturn] = attr_AttrReq_NoArg, +< [attr_AttrKind_Inline] = attr_AttrReq_NoArg, +< [attr_AttrKind_PrintfFormat] = attr_AttrReq_NoArg, +< [attr_AttrKind_ScanfFormat] = attr_AttrReq_NoArg, +< [attr_AttrKind_Aligned] = attr_AttrReq_Number, +< [attr_AttrKind_Weak] = attr_AttrReq_NoArg, +< [attr_AttrKind_Opaque] = attr_AttrReq_NoArg, +< [attr_AttrKind_CName] = attr_AttrReq_String, +< [attr_AttrKind_CDef] = attr_AttrReq_String, +< [attr_AttrKind_NoTypeDef] = attr_AttrReq_NoArg, +< [attr_AttrKind_Constructor] = attr_AttrReq_NoArg, +< [attr_AttrKind_Destructor] = attr_AttrReq_NoArg, +< [attr_AttrKind_Pure] = attr_AttrReq_NoArg, +< [attr_AttrKind_AutoFile] = attr_AttrReq_NoArg, +< [attr_AttrKind_AutoLine] = attr_AttrReq_NoArg, +< [attr_AttrKind_AutoFunc] = attr_AttrReq_NoArg, +< [attr_AttrKind_Embed] = attr_AttrReq_String, +< [attr_AttrKind_Deprecated] = attr_AttrReq_String +--- +> static const attr_AttrReq attr_AttrKind__required_arg[24] = { +> attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_NoArg, +> attr_AttrReq_String, attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_NoArg, +> attr_AttrReq_Number, attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_String, attr_AttrReq_String, +> attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_NoArg, +> attr_AttrReq_NoArg, attr_AttrReq_NoArg, attr_AttrReq_String, attr_AttrReq_String +5771c5830 +< return attr_attrKind_names[a->kind]; +--- +> return attr_AttrKind__name[a->kind]; +5776,5778c5835,5838 +< ar->name_indexes[0] = 0; +< for (attr_AttrKind kind = (attr_AttrKind)1; kind <= attr_AttrKind_Deprecated; kind++) { +< ar->name_indexes[kind] = string_pool_Pool_addStr(pool, attr_attrKind_names[kind], true); +--- +> attr_AttrKind kind = (attr_AttrKind)0; +> ar->name_indexes[kind++] = 0; +> for (; kind <= attr_AttrKind_Deprecated; kind++) { +> ar->name_indexes[kind] = string_pool_Pool_addStr(pool, attr_AttrKind__name[kind], true); +5797c5857 +< switch (attr_Required_arg[a->kind]) { +--- +> switch (attr_AttrKind__required_arg[a->kind]) { +5848c5908 +< attr_table_Table* t = calloc(1, 16); +--- +> attr_table_Table* t = calloc(1, 12); +5862c5922 +< attr_Attr* attrs2 = malloc(capacity * 32); +--- +> attr_Attr* attrs2 = malloc(capacity * 24); +5864c5924 +< memcpy(attrs2, t->attrs, t->count * 32); +--- +> memcpy(attrs2, t->attrs, t->count * 24); +5918a5979 +> typedef struct ast_VarDeclList_ ast_VarDeclList; +5923a5985 +> typedef struct ast_BreakStmtBits_ ast_BreakStmtBits; +5926a5989 +> typedef struct ast_ContinueStmtBits_ ast_ContinueStmtBits; +6200c6263,6264 +< static const char* ast_declKind_names[8] = { +--- +> #define ast_NumDeclBits 15 +> static const char* const ast_DeclKind__name[8] = { +6204,6205c6268,6339 +< static const char* ast_declCheckState_names[3] = { "unchecked", "in-progress", "checked" }; +< #define ast_NumDeclBits 15 +--- +> static const char* const ast_DeclCheckState__name[3] = { "unchecked", "in-progress", "checked" }; +> static const char* const ast_CallKind__name[4] = { "Invalid", "Normal", "SF", "SSF" }; +> static const char* const ast_DefKind__name[6] = { +> "global", "type", "struct-member", "param", "enum-value", "template" +> }; +> static const char* const ast_VarDeclKind__name[5] = { "global", "local", "parameter", "member", "enum-value" }; +> static const char* const ast_StmtKind__name[15] = { +> "ReturnStmt", "ExprStmt", "IfStmt", "WhileStmt", "ForStmt", +> "SwitchStmt", "BreakStmt", "ContinueStmt", "FallthroughStmt", "LabelStmt", +> "GotoStmt", "CompoundStmt", "DeclStmt", "Asm", "AssertStmt" +> }; +> static const char* const ast_ExprKind__name[25] = { +> "IntegerLiteral", "FloatLiteral", "BooleanLiteral", "CharLiteral", +> "StringLiteral", "Nil", "Identifier", "TypeExpr", +> "Call", "InitList", "FieldDesignatedInit", "ArrayDesignatedInit", +> "BinaryOperator", "UnaryOperator", "ConditionalOp", "Builtin", +> "ArraySubscript", "Member", "Paren", "BitOffset", +> "ExplicitCast", "ImplicitCast", "RangeExpr", "NamedArgument", +> "Alternate" +> }; +> static const char* const ast_ValType__name[3] = { "nvalue", "rvalue", "lvalue" }; +> static const char* const ast_BinaryOpcode__name[29] = { +> "*", "/", "%", "+", "-", "<<", ">>", "<", ">", "<=", +> ">=", "==", "!=", "&", "^", "|", "&&", "||", "=", "*=", +> "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|=" +> }; +> #define ast_RHS 0x02 +> #define ast_LHS 0x01 +> static const u32 ast_BinaryOpcode__side[29] = { +> ast_RHS, ast_RHS, ast_RHS, ast_RHS, ast_RHS, +> ast_RHS, ast_RHS, ast_RHS, ast_RHS, ast_RHS, +> ast_RHS, ast_RHS, ast_RHS, ast_RHS, ast_RHS, +> ast_RHS, ast_RHS, ast_RHS, ast_LHS, ast_LHS | ast_RHS, +> ast_LHS | ast_RHS, ast_LHS | ast_RHS, ast_LHS | ast_RHS, ast_LHS | ast_RHS, ast_LHS | ast_RHS, +> ast_LHS | ast_RHS, ast_LHS | ast_RHS, ast_LHS | ast_RHS, ast_LHS | ast_RHS +> }; +> static const char* const ast_BuiltinExprKind__name[4] = { "sizeof", "elemsof", "offsetof", "to_container" }; +> static const char* const ast_IdentifierKind__name[8] = { +> "Unresolved", "Module", "Function", "Type", +> "Var", "EnumConstant", "StructMember", "Label" +> }; +> static const char* const ast_ImplicitCastKind__name[6] = { +> "ArrayToPointerDecay", "LValueToRValue", "PointerToBoolean", "PointerToInteger", +> "IntegralCast", "BitCast" +> }; +> static const char* const ast_MemberKind__name[8] = { +> "Unresolved", "Module", "StructMember", "TypeFunc", +> "StaticTypeFunc", "EnumConstant", "EnumAssocValue", "EnumConstantValue" +> }; +> static const char* const ast_UnaryOpcode__name[10] = { "++", "--", "++", "--", "&", "*", "+", "-", "~", "!" }; +> static const char* const ast_TypeKind__name[9] = { +> "Builtin", "Pointer", "Array", "Struct", "Enum", "Function", "Void", "Alias", +> "Module" +> }; +> static const char* const ast_BuiltinKind__name[14] = { +> "bool", "char", "i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", +> "f32", "f64", "isize", "usize" +> }; +> static const bool ast_BuiltinKind__promotable[14] = { +> true, true, true, true, false, false, true, true, false, false, false, false, false, false +> }; +> static const bool ast_BuiltinKind__is_signed[14] = { +> false, false, true, true, true, true, false, false, false, false, true, true, true, false +> }; +> static const bool ast_BuiltinKind__is_unsigned[14] = { +> false, true, false, false, false, false, true, true, true, true, false, false, false, true +> }; +> static const bool ast_BuiltinKind__is_integer[14] = { +> false, true, true, true, true, true, true, true, true, true, false, false, true, true +> }; +> static const u8 ast_BuiltinKind__align[14] = { 1, 1, 1, 2, 4, 8, 1, 2, 4, 8, 4, 8, 0, 0 }; +> static const u8 ast_BuiltinKind__width[14] = { 1, 8, 8, 16, 32, 64, 8, 16, 32, 64, 0, 0, 0, 0 }; +6235d6368 +< static u32 ast_Decl_getASTIdx(const ast_Decl* d); +6254c6387 +< static const char* ast_Decl_getCName(const ast_Decl* d); +--- +> static u32 ast_Decl_getCName(const ast_Decl* d); +6256,6257c6389,6390 +< static const char* ast_Decl_getCDef(const ast_Decl* d); +< static const char* ast_Decl_getSection(const ast_Decl* d); +--- +> static u32 ast_Decl_getCDef(const ast_Decl* d); +> static u32 ast_Decl_getSection(const ast_Decl* d); +6274a6408 +> ast_BuiltinKind_Bool, +6288d6421 +< ast_BuiltinKind_Bool, +6371a6505,6509 +> struct ast_BreakStmtBits_ { +> u32 : 4; +> u32 has_name : 1; +> }; +> +6376a6515,6519 +> struct ast_ContinueStmtBits_ { +> u32 : 4; +> u32 has_name : 1; +> }; +> +6378a6522,6523 +> u32 has_decl : 1; +> u32 has_source_cond : 1; +6384a6530,6532 +> u32 has_goto : 1; +> u32 has_break : 1; +> u32 has_continue : 1; +6397c6545 +< u32 has_cond : 1; +--- +> u32 has_source_cond : 1; +6518,6519d6665 +< ast_BuiltinExprKind_EnumMin, +< ast_BuiltinExprKind_EnumMax, +6526,6527c6672,6673 +< u8 : 2; +< ast_BuiltinExprKind kind : 3; +--- +> ast_BuiltinExprKind kind : 2; +> bool use_literal : 1; +6682a6829 +> ast_BreakStmtBits breakStmtBits; +6683a6831 +> ast_ContinueStmtBits continueStmtBits; +6806,6809d6953 +< static const char* ast_callKind_names[4] = { "Invalid", "Normal", "SF", "SSF" }; +< static const char* ast_defKind_names[6] = { +< "global", "type", "struct-member", "param", "enum-value", "template" +< }; +6839,6840c6983,6984 +< static const char* ast_FunctionDecl_getCName(const ast_FunctionDecl* d); +< static const char* ast_FunctionDecl_getPrefixName(const ast_FunctionDecl* d); +--- +> static u32 ast_FunctionDecl_getCName(const ast_FunctionDecl* d); +> static u32 ast_FunctionDecl_getPrefixNameIdx(const ast_FunctionDecl* d); +6871,6894d7014 +< typedef int (*ast_FunII)(int a); +< +< typedef int (*ast_FunIF)(float a); +< +< typedef int (*ast_FunID)(double a); +< +< typedef i64 (*ast_FunLL)(i64 a); +< +< typedef i64 (*ast_FunLF)(float a); +< +< typedef i64 (*ast_FunLD)(double a); +< +< typedef float (*ast_FunFF)(float a); +< +< typedef double (*ast_FunDD)(double a); +< +< typedef float (*ast_FunFFF)(float a, float b); +< +< typedef double (*ast_FunDDD)(double a, double b); +< +< typedef float (*ast_FunFFFF)(float a, float b, float c); +< +< typedef double (*ast_FunDDDD)(double a, double b, double c); +< +6897,6908c7017,7028 +< ast_FunII funII; +< ast_FunIF funIF; +< ast_FunID funID; +< ast_FunLL funLL; +< ast_FunLF funLF; +< ast_FunLD funLD; +< ast_FunFF funFF; +< ast_FunDD funDD; +< ast_FunFFF funFFF; +< ast_FunDDD funDDD; +< ast_FunFFFF funFFFF; +< ast_FunDDDD funDDDD; +--- +> int (*funII)(int a); +> int (*funIF)(float a); +> int (*funID)(double a); +> i64 (*funLL)(i64 a); +> i64 (*funLF)(float a); +> i64 (*funLD)(double a); +> float (*funFF)(float a); +> double (*funDD)(double a); +> float (*funFFF)(float a, float b); +> double (*funDDD)(double a, double b); +> float (*funFFFF)(float a, float b, float c); +> double (*funDDDD)(double a, double b, double c); +6917c7037 +< static ast_FunctionTypeDecl* ast_FunctionTypeDecl_create(ast_context_Context* c, ast_FunctionDecl* func); +--- +> static ast_FunctionTypeDecl* ast_FunctionTypeDecl_create(ast_context_Context* c, ast_FunctionDecl* func, u32 ast_idx); +6930d7049 +< static const char* ast_ImportDecl_getAliasName(const ast_ImportDecl* d); +7044d7162 +< static const char* ast_varDeclNames[5] = { " global", " local", " parameter", " member", " enum-value" }; +7048,7049d7165 +< static const char* ast_VarDecl_getEnumAssocValueName(const ast_VarDecl* d, const char* enum_name); +< static const char* ast_VarDecl_getName(const ast_VarDecl* d); +7094,7097c7210,7214 +< static const char* ast_stmtKind_names[15] = { +< "ReturnStmt", "ExprStmt", "IfStmt", "WhileStmt", "ForStmt", +< "SwitchStmt", "BreakStmt", "ContinueStmt", "FallthroughStmt", "LabelStmt", +< "GotoStmt", "CompoundStmt", "DeclStmt", "Asm", "AssertStmt" +--- +> struct ast_VarDeclList_ { +> u32 count; +> u32 capacity; +> ast_VarDecl** data; +> ast_VarDecl* stash[4]; +7098a7216,7222 +> +> static void ast_VarDeclList_init(ast_VarDeclList* l); +> static void ast_VarDeclList_free(ast_VarDeclList* l); +> static void ast_VarDeclList_resize(ast_VarDeclList* l); +> static void ast_VarDeclList_add(ast_VarDeclList* l, ast_VarDecl* d); +> static u32 ast_VarDeclList_size(const ast_VarDeclList* l); +> static ast_VarDecl** ast_VarDeclList_getData(const ast_VarDeclList* l); +7153a7278 +> u32 name_idx[0]; +7156c7281,7283 +< static ast_BreakStmt* ast_BreakStmt_create(ast_context_Context* c, src_loc_SrcLoc loc); +--- +> static ast_BreakStmt* ast_BreakStmt_create(ast_context_Context* c, src_loc_SrcLoc loc, u32 name_idx); +> static bool ast_BreakStmt_hasName(const ast_BreakStmt* s); +> static u32 ast_BreakStmt_getName(const ast_BreakStmt* s); +7170a7298 +> u32 name_idx[0]; +7173c7301,7303 +< static ast_ContinueStmt* ast_ContinueStmt_create(ast_context_Context* c, src_loc_SrcLoc loc); +--- +> static ast_ContinueStmt* ast_ContinueStmt_create(ast_context_Context* c, src_loc_SrcLoc loc, u32 name_idx); +> static bool ast_ContinueStmt_hasName(const ast_ContinueStmt* s); +> static u32 ast_ContinueStmt_getName(const ast_ContinueStmt* s); +7206d7335 +< static const char* ast_GotoStmt_getName(const ast_GotoStmt* g); +7211c7340 +< ast_Stmt* cond; +--- +> ast_Expr* cond; +7213c7342 +< ast_Stmt* else_stmt[0]; +--- +> ast_Stmt* tail[0]; +7216c7345 +< static ast_IfStmt* ast_IfStmt_create(ast_context_Context* c, src_loc_SrcLoc loc, ast_Stmt* cond, ast_Stmt* then, ast_Stmt* else_stmt); +--- +> static ast_IfStmt* ast_IfStmt_create(ast_context_Context* c, src_loc_SrcLoc loc, ast_Stmt* decl, ast_Expr* cond, ast_Stmt* then, ast_Stmt* else_stmt); +7218,7219c7347,7352 +< static ast_Stmt* ast_IfStmt_getCond(const ast_IfStmt* s); +< static ast_Stmt** ast_IfStmt_getCond2(ast_IfStmt* s); +--- +> static bool ast_IfStmt_hasDecl(const ast_IfStmt* s); +> static ast_Stmt* ast_IfStmt_getDecl(const ast_IfStmt* s); +> static ast_Stmt** ast_IfStmt_getDecl2(ast_IfStmt* s); +> static bool ast_IfStmt_hasSourceCond(const ast_IfStmt* s); +> static ast_Expr* ast_IfStmt_getCond(const ast_IfStmt* s); +> static ast_Expr** ast_IfStmt_getCond2(ast_IfStmt* s); +7221a7355 +> static bool ast_IfStmt_hasElse(const ast_IfStmt* s); +7235c7369,7374 +< static const char* ast_LabelStmt_getName(const ast_LabelStmt* s); +--- +> static bool ast_LabelStmt_hasGoto(const ast_LabelStmt* s); +> static void ast_LabelStmt_setGoto(ast_LabelStmt* s); +> static bool ast_LabelStmt_hasBreak(const ast_LabelStmt* s); +> static void ast_LabelStmt_setBreak(ast_LabelStmt* s); +> static bool ast_LabelStmt_hasContinue(const ast_LabelStmt* s); +> static void ast_LabelStmt_setContinue(ast_LabelStmt* s); +7293c7432 +< static bool ast_SwitchStmt_hasCond(const ast_SwitchStmt* s); +--- +> static bool ast_SwitchStmt_hasSourceCond(const ast_SwitchStmt* s); +7320,7329d7458 +< static const char* ast_exprKind_names[25] = { +< "IntegerLiteral", "FloatLiteral", "BooleanLiteral", "CharLiteral", +< "StringLiteral", "Nil", "Identifier", "TypeExpr", +< "Call", "InitList", "FieldDesignatedInit", "ArrayDesignatedInit", +< "BinaryOperator", "UnaryOperator", "ConditionalOp", "Builtin", +< "ArraySubscript", "Member", "Paren", "BitOffset", +< "ExplicitCast", "ImplicitCast", "RangeExpr", "NamedArgument", +< "Alternate" +< }; +< static const char* ast_valType_names[3] = { "nvalue", "rvalue", "lvalue" }; +7449,7453d7577 +< static const char* ast_binaryOpcode_names[29] = { +< "*", "/", "%", "+", "-", "<<", ">>", "<", ">", "<=", +< ">=", "==", "!=", "&", "^", "|", "&&", "||", "=", "*=", +< "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|=" +< }; +7455d7578 +< static const char* ast_BinaryOpcode_str(ast_BinaryOpcode opcode); +7507c7630 +< value_type_Value value; +--- +> u64 value; +7512,7514d7634 +< static const char* ast_builtin_names[6] = { +< "sizeof", "elemsof", "enum_min", "enum_max", "offsetof", "to_container" +< }; +7520,7522c7640,7642 +< static value_type_Value ast_BuiltinExpr_getValue(const ast_BuiltinExpr* e); +< static void ast_BuiltinExpr_setValue(ast_BuiltinExpr* e, value_type_Value value); +< static void ast_BuiltinExpr_setUValue(ast_BuiltinExpr* e, u64 val); +--- +> static u64 ast_BuiltinExpr_useLiteral(const ast_BuiltinExpr* e); +> static u64 ast_BuiltinExpr_getValue(const ast_BuiltinExpr* e); +> static void ast_BuiltinExpr_setValue(ast_BuiltinExpr* e, u64 val); +7644d7763 +< static const char* ast_IdentifierKind_str(ast_IdentifierKind k); +7664,7667d7782 +< static const char* ast_implicitCastKind_names[6] = { +< "ArrayToPointerDecay", "LValueToRValue", "PointerToBoolean", "PointerToInteger", +< "IntegralCast", "BitCast" +< }; +7722d7836 +< static const char* ast_MemberKind_str(ast_MemberKind k); +7810c7924 +< u32 size; +--- +> u32 len; +7814,7816c7928,7929 +< static const char* ast_StringLiteral_getText(const ast_StringLiteral* e); +< static u32 ast_StringLiteral_getTextIndex(const ast_StringLiteral* e); +< static u32 ast_StringLiteral_getSize(const ast_StringLiteral* e); +--- +> static u32 ast_StringLiteral_getText(const ast_StringLiteral* e); +> static u32 ast_StringLiteral_getLength(const ast_StringLiteral* e); +7836d7948 +< static const char* ast_unaryOpcode_names[10] = { "++", "--", "++", "--", "&", "*", "+", "-", "~", "!" }; +7862a7975 +> u32 align : 8; +7866c7979 +< u32 : 8; +--- +> u32 : 16; +7867a7981,7982 +> ast_BuiltinKind base_kind : 4; +> u32 width : 8; +7871c7986 +< u32 : 8; +--- +> u32 : 16; +7888c8003 +< #define ast_NumTypeBits 8 +--- +> #define ast_NumTypeBits 16 +7890a8006 +> static ast_QualType ast_Type_getCanonicalType(const ast_Type* t); +7899a8016,8017 +> static void ast_Type_setAlignment(ast_Type* t, u32 align); +> static u32 ast_Type_getAlignment(const ast_Type* t); +7934,8046d8051 +< static const char* ast_builtinType_names[14] = { +< [ast_BuiltinKind_Char] = "char", +< [ast_BuiltinKind_Int8] = "i8", +< [ast_BuiltinKind_Int16] = "i16", +< [ast_BuiltinKind_Int32] = "i32", +< [ast_BuiltinKind_Int64] = "i64", +< [ast_BuiltinKind_UInt8] = "u8", +< [ast_BuiltinKind_UInt16] = "u16", +< [ast_BuiltinKind_UInt32] = "u32", +< [ast_BuiltinKind_UInt64] = "u64", +< [ast_BuiltinKind_Float32] = "f32", +< [ast_BuiltinKind_Float64] = "f64", +< [ast_BuiltinKind_ISize] = "isize", +< [ast_BuiltinKind_USize] = "usize", +< [ast_BuiltinKind_Bool] = "bool" +< }; +< static const bool ast_BuiltinType_promotable[14] = { +< [ast_BuiltinKind_Char] = true, +< [ast_BuiltinKind_Int8] = true, +< [ast_BuiltinKind_Int16] = true, +< [ast_BuiltinKind_Int32] = false, +< [ast_BuiltinKind_Int64] = false, +< [ast_BuiltinKind_UInt8] = true, +< [ast_BuiltinKind_UInt16] = true, +< [ast_BuiltinKind_UInt32] = false, +< [ast_BuiltinKind_UInt64] = false, +< [ast_BuiltinKind_Float32] = false, +< [ast_BuiltinKind_Float64] = false, +< [ast_BuiltinKind_ISize] = false, +< [ast_BuiltinKind_USize] = false, +< [ast_BuiltinKind_Bool] = true +< }; +< static const bool ast_BuiltinType_signed[14] = { +< [ast_BuiltinKind_Char] = false, +< [ast_BuiltinKind_Int8] = true, +< [ast_BuiltinKind_Int16] = true, +< [ast_BuiltinKind_Int32] = true, +< [ast_BuiltinKind_Int64] = true, +< [ast_BuiltinKind_UInt8] = false, +< [ast_BuiltinKind_UInt16] = false, +< [ast_BuiltinKind_UInt32] = false, +< [ast_BuiltinKind_UInt64] = false, +< [ast_BuiltinKind_Float32] = true, +< [ast_BuiltinKind_Float64] = true, +< [ast_BuiltinKind_ISize] = true, +< [ast_BuiltinKind_USize] = false, +< [ast_BuiltinKind_Bool] = false +< }; +< static const bool ast_BuiltinType_unsigned[14] = { +< [ast_BuiltinKind_Char] = true, +< [ast_BuiltinKind_Int8] = false, +< [ast_BuiltinKind_Int16] = false, +< [ast_BuiltinKind_Int32] = false, +< [ast_BuiltinKind_Int64] = false, +< [ast_BuiltinKind_UInt8] = true, +< [ast_BuiltinKind_UInt16] = true, +< [ast_BuiltinKind_UInt32] = true, +< [ast_BuiltinKind_UInt64] = true, +< [ast_BuiltinKind_Float32] = false, +< [ast_BuiltinKind_Float64] = false, +< [ast_BuiltinKind_ISize] = false, +< [ast_BuiltinKind_USize] = true, +< [ast_BuiltinKind_Bool] = false +< }; +< static const bool ast_BuiltinType_integer[14] = { +< [ast_BuiltinKind_Char] = true, +< [ast_BuiltinKind_Int8] = true, +< [ast_BuiltinKind_Int16] = true, +< [ast_BuiltinKind_Int32] = true, +< [ast_BuiltinKind_Int64] = true, +< [ast_BuiltinKind_UInt8] = true, +< [ast_BuiltinKind_UInt16] = true, +< [ast_BuiltinKind_UInt32] = true, +< [ast_BuiltinKind_UInt64] = true, +< [ast_BuiltinKind_Float32] = false, +< [ast_BuiltinKind_Float64] = false, +< [ast_BuiltinKind_ISize] = true, +< [ast_BuiltinKind_USize] = true, +< [ast_BuiltinKind_Bool] = false +< }; +< static const u32 ast_BuiltinType_default_sizes[14] = { +< [ast_BuiltinKind_Char] = 1, +< [ast_BuiltinKind_Int8] = 1, +< [ast_BuiltinKind_Int16] = 2, +< [ast_BuiltinKind_Int32] = 4, +< [ast_BuiltinKind_Int64] = 8, +< [ast_BuiltinKind_UInt8] = 1, +< [ast_BuiltinKind_UInt16] = 2, +< [ast_BuiltinKind_UInt32] = 4, +< [ast_BuiltinKind_UInt64] = 8, +< [ast_BuiltinKind_Float32] = 4, +< [ast_BuiltinKind_Float64] = 8, +< [ast_BuiltinKind_ISize] = 8, +< [ast_BuiltinKind_USize] = 8, +< [ast_BuiltinKind_Bool] = 1 +< }; +< static const u32 ast_BuiltinType_default_widths[14] = { +< [ast_BuiltinKind_Char] = 8, +< [ast_BuiltinKind_Int8] = 8, +< [ast_BuiltinKind_Int16] = 16, +< [ast_BuiltinKind_Int32] = 32, +< [ast_BuiltinKind_Int64] = 64, +< [ast_BuiltinKind_UInt8] = 8, +< [ast_BuiltinKind_UInt16] = 16, +< [ast_BuiltinKind_UInt32] = 32, +< [ast_BuiltinKind_UInt64] = 64, +< [ast_BuiltinKind_Float32] = 0, +< [ast_BuiltinKind_Float64] = 0, +< [ast_BuiltinKind_ISize] = 64, +< [ast_BuiltinKind_USize] = 64, +< [ast_BuiltinKind_Bool] = 1 +< }; +< static const char* ast_BuiltinKind_str(ast_BuiltinKind kind); +8050d8054 +< static ast_BuiltinKind ast_BuiltinType_getBuiltinKind(const ast_BuiltinType* b); +8053d8056 +< static const char* ast_BuiltinType_kind2str(const ast_BuiltinType* b); +8072d8074 +< static const char* ast_EnumType_getName(const ast_EnumType* t); +8130a8133 +> static u32 ast_QualType_getAlignment(const ast_QualType qt); +8163a8167 +> static void ast_QualType_setTypeUsedPublic(ast_QualType qt); +8188c8192 +< static const char* ast_Ref_getName(const ast_Ref* r); +--- +> static u32 ast_Ref_getNameIdx(const ast_Ref* r); +8189a8194 +> static void ast_TypeRefHolder_copy(ast_TypeRefHolder* h, const ast_TypeRef* ref); +8271c8276 +< ast_Decl** decls; +--- +> ast_Decl** data; +8322d8326 +< static const char* ast_AST_getName(const ast_AST* a); +8353d8356 +< static void ast_DeclList_add(ast_DeclList* l, ast_Decl* d); +8354a8358,8359 +> static void ast_DeclList_resize(ast_DeclList* l); +> static void ast_DeclList_add(ast_DeclList* l, ast_Decl* d); +8357c8362 +< static ast_Decl** ast_DeclList_getDecls(const ast_DeclList* l); +--- +> static ast_Decl** ast_DeclList_getData(const ast_DeclList* l); +8506a8512 +> static void ast_PointerPool_report(const ast_PointerPool* p); +8528a8535 +> static void ast_StringTypePool_report(const ast_StringTypePool* p); +8546d8552 +< u32 wordsize; +8551,8553d8556 +< u32 builtinType_sizes[14]; +< u32 builtinType_width[14]; +< ast_BuiltinKind builtinType_baseTypes[14]; +8564c8567 +< static color_Color ast_col_Attr = color_Color_Blue; +--- +> static color_Color ast_col_Attr = color_Color_Bblue; +8572,8574c8575,8577 +< static void ast_initialize(ast_context_Context* c, string_pool_Pool* astPool, u32 wordsize, bool use_color); +< static void ast_deinit(bool print_stats); +< static u32 ast_getWordSize(void); +--- +> static void ast_initialize(ast_context_Context* c, string_pool_Pool* astPool, bool use_color); +> static void ast_report(void); +> static void ast_deinit(void); +8581,8582c8584,8585 +< static u32 ast_addAST(ast_AST* ast_); +< static ast_AST* ast_idx2ast(u32 idx); +--- +> static u32 ast_Globals_addAST(ast_Globals* g, ast_AST* a); +> static ast_AST* ast_Globals_idx2ast(ast_Globals* g, u32 idx); +8585,8586d8587 +< static void ast_setTypePublicUsed(ast_QualType qt); +< static ast_BuiltinKind ast_getNativeKind(void); +8693a8695 +> d->declBits.has_attr = 1; +8699c8701,8704 +< if (d->declBits.is_public) d->declBits.attr_export = 1; +--- +> if (d->declBits.is_public) { +> d->declBits.has_attr = 1; +> d->declBits.attr_export = 1; +> } +8722a8728 +> d->declBits.has_attr = 1; +8796,8801c8802 +< return ast_idx2ast(d->ast_idx); +< } +< +< static u32 ast_Decl_getASTIdx(const ast_Decl* d) +< { +< return d->ast_idx; +--- +> return ast_Globals_idx2ast(ast_globals, d->ast_idx); +8937c8938 +< static const char* ast_Decl_getCName(const ast_Decl* d) +--- +> static u32 ast_Decl_getCName(const ast_Decl* d) +8940,8941c8941,8942 +< if (cname) return ast_idx2name(cname->value.text); +< return NULL; +--- +> if (cname) return cname->value.text; +> return 0; +8949c8950 +< static const char* ast_Decl_getCDef(const ast_Decl* d) +--- +> static u32 ast_Decl_getCDef(const ast_Decl* d) +8952,8953c8953,8954 +< if (cdef) return ast_idx2name(cdef->value.text); +< return NULL; +--- +> if (cdef) return cdef->value.text; +> return 0; +8956c8957 +< static const char* ast_Decl_getSection(const ast_Decl* d) +--- +> static u32 ast_Decl_getSection(const ast_Decl* d) +8959,8960c8960,8961 +< if (section) return ast_idx2name(section->value.text); +< return NULL; +--- +> if (section) return section->value.text; +> return 0; +8974c8975,8976 +< snprintf(tmp, tmp_size, "%s.%s.%s", modname, ast_FunctionDecl_getPrefixName(fd), ast_Decl_getName(d)); +--- +> const char* prefix_name = ast_idx2name(ast_FunctionDecl_getPrefixNameIdx(fd)); +> snprintf(tmp, tmp_size, "%s.%s.%s", modname, prefix_name, ast_Decl_getName(d)); +9032c9034 +< string_buffer_Buf_add(out, ast_declKind_names[ast_Decl_getKind(d)]); +--- +> string_buffer_Buf_add(out, ast_DeclKind__name[ast_Decl_getKind(d)]); +9057c9059 +< string_buffer_Buf_add(out, ast_declCheckState_names[cs]); +--- +> string_buffer_Buf_add(out, ast_DeclCheckState__name[cs]); +9136c9138 +< ast_ArrayValue* d = ast_context_Context_alloc(c, 16); +--- +> ast_ArrayValue* d = ast_context_Context_alloc(c, 12); +9160c9162 +< u32 size = 8 + 8 * count; +--- +> u32 size = 8 + 4 * count; +9164c9166 +< memcpy(s->decl, decl, 8 * count); +--- +> memcpy(s->decl, decl, 4 * count); +9197c9199 +< if (initValue) size += 8; +--- +> if (initValue) size += 4; +9258,9259c9260,9261 +< u32 size = 64 + num_constants * 8; +< if (is_incremental) size += 8; +--- +> u32 size = 40 + num_constants * 4; +> if (is_incremental) size += 4; +9277c9279 +< memcpy(d->constants, constants, num_constants * 8); +--- +> memcpy(d->constants, constants, num_constants * 4); +9283c9285 +< u32 assoc_size = num_assoc_values * 8; +--- +> u32 assoc_size = num_assoc_values * 4; +9340c9342 +< const u32 size = count * 8; +--- +> const u32 size = count * 4; +9406c9408 +< const u32 size = count * 8; +--- +> const u32 size = count * 4; +9463c9465 +< u32 size = 80 + num_params * 8 + ast_TypeRefHolder_getExtraSize(rtype); +--- +> u32 size = 64 + num_params * 4 + ast_TypeRefHolder_getExtraSize(rtype); +9487c9489 +< memcpy(tail, params, num_params * 8); +--- +> memcpy(tail, params, num_params * 4); +9494c9496 +< u32 size = 80 + num_params * 8 + ast_TypeRefHolder_getExtraSize(rtype); +--- +> u32 size = 64 + num_params * 4 + ast_TypeRefHolder_getExtraSize(rtype); +9514c9516 +< memcpy(tail, params, num_params * 8); +--- +> memcpy(tail, params, num_params * 4); +9524c9526 +< u32 size = 80 + num_params * 8 + extra; +--- +> u32 size = 64 + num_params * 4 + extra; +9693c9695 +< if (d->flags.instance_ast_idx) return ast_AST_getMod(ast_idx2ast(d->flags.instance_ast_idx)); +--- +> if (d->flags.instance_ast_idx) return ast_AST_getMod(ast_Globals_idx2ast(ast_globals, d->flags.instance_ast_idx)); +9703c9705 +< static const char* ast_FunctionDecl_getCName(const ast_FunctionDecl* d) +--- +> static u32 ast_FunctionDecl_getCName(const ast_FunctionDecl* d) +9705,9707c9707,9709 +< const char* cname = ast_Decl_getCName(&d->base); +< if (!cname) cname = ast_Decl_getName(&d->base); +< return cname; +--- +> u32 cname = ast_Decl_getCName(&d->base); +> if (cname) return cname; +> return ast_Decl_getNameIdx(&d->base); +9710c9712 +< static const char* ast_FunctionDecl_getPrefixName(const ast_FunctionDecl* d) +--- +> static u32 ast_FunctionDecl_getPrefixNameIdx(const ast_FunctionDecl* d) +9712,9713c9714,9715 +< if (!ast_FunctionDecl_hasPrefix(d)) return NULL; +< return ast_Ref_getName(&d->prefix); +--- +> if (!ast_FunctionDecl_hasPrefix(d)) return 0; +> return ast_Ref_getNameIdx(&d->prefix); +9871c9873 +< string_buffer_Buf_add(out, ast_callKind_names[ast_FunctionDecl_getCallKind(d)]); +--- +> string_buffer_Buf_add(out, ast_CallKind__name[ast_FunctionDecl_getCallKind(d)]); +9874c9876 +< string_buffer_Buf_add(out, ast_defKind_names[ast_FunctionDecl_getDefKind(d)]); +--- +> string_buffer_Buf_add(out, ast_DefKind__name[ast_FunctionDecl_getDefKind(d)]); +9901c9903 +< string_buffer_Buf_add(out, ast_Ref_getName(&d->prefix)); +--- +> string_buffer_Buf_add(out, ast_idx2name(ast_Ref_getNameIdx(&d->prefix))); +10003c10005 +< static ast_FunctionTypeDecl* ast_FunctionTypeDecl_create(ast_context_Context* c, ast_FunctionDecl* func) +--- +> static ast_FunctionTypeDecl* ast_FunctionTypeDecl_create(ast_context_Context* c, ast_FunctionDecl* func, u32 ast_idx) +10005c10007 +< ast_FunctionTypeDecl* ftd = ast_context_Context_alloc(c, 32); +--- +> ast_FunctionTypeDecl* ftd = ast_context_Context_alloc(c, 24); +10007c10009 +< ast_Decl_init(&ftd->base, ast_DeclKind_FunctionType, ast_Decl_getNameIdx(d), ast_Decl_getLoc(d), ast_Decl_isPublic(d), ast_Decl_getType(d), ast_Decl_getASTIdx(d)); +--- +> ast_Decl_init(&ftd->base, ast_DeclKind_FunctionType, ast_Decl_getNameIdx(d), ast_Decl_getLoc(d), ast_Decl_isPublic(d), ast_Decl_getType(d), ast_idx); +10034c10036 +< ast_ImportDecl* d = ast_context_Context_alloc(c, 40); +--- +> ast_ImportDecl* d = ast_context_Context_alloc(c, 32); +10048,10052d10049 +< static const char* ast_ImportDecl_getAliasName(const ast_ImportDecl* d) +< { +< return ast_idx2name(d->alias_idx); +< } +< +10113c10110 +< ast_StaticAssert* d = ast_context_Context_alloc(c, 24); +--- +> ast_StaticAssert* d = ast_context_Context_alloc(c, 16); +10123c10120 +< return ast_idx2ast(d->ast_idx); +--- +> return ast_Globals_idx2ast(ast_globals, d->ast_idx); +10164c10161 +< u32 size = 48 + num_members * 8; +--- +> u32 size = 36 + num_members * 4; +10184c10181 +< memcpy(d->members, members, num_members * 8); +--- +> memcpy(d->members, members, num_members * 4); +10291c10288 +< const u32 size = count * 8; +--- +> const u32 size = count * 4; +10356c10353 +< d->field_info = ast_context_Context_alloc(c, 8 + count * 24); +--- +> d->field_info = ast_context_Context_alloc(c, 8 + count * 20); +10442c10439 +< if (initValue || ast_TypeRefHolder_isIncrArray(ref) || has_embed) size += 16; +--- +> if (initValue || ast_TypeRefHolder_isIncrArray(ref) || has_embed) size += 8; +10460c10457 +< if (bitfield) size += 16; +--- +> if (bitfield) size += 12; +10481,10482c10478,10479 +< if (vd->base.varDeclBits.has_init) extra += 16; +< if (vd->base.varDeclBits.is_bitfield) extra += 16; +--- +> if (vd->base.varDeclBits.has_init) extra += 8; +> if (vd->base.varDeclBits.is_bitfield) extra += 12; +10502,10516d10498 +< static const char* ast_VarDecl_getEnumAssocValueName(const ast_VarDecl* d, const char* enum_name) +< { +< static char tmp_buf[2][128]; +< static u32 tmp_id = 0; +< u32 tmp_size = 128; +< char* tmp = tmp_buf[tmp_id++ & 1]; +< snprintf(tmp, tmp_size, "%s.%s", enum_name, ast_VarDecl_getName(d)); +< return tmp; +< } +< +< static const char* ast_VarDecl_getName(const ast_VarDecl* d) +< { +< return ast_idx2name(d->base.name_idx); +< } +< +10689a10672 +> d->base.declBits.has_attr = 1; +10704a10688 +> d->base.declBits.has_attr = 1; +10714a10699 +> d->base.declBits.has_attr = 1; +10724a10710 +> d->base.declBits.has_attr = 1; +10739a10726 +> d->base.declBits.has_attr = 1; +10758c10745,10746 +< string_buffer_Buf_add(out, ast_varDeclNames[k]); +--- +> string_buffer_Buf_space(out); +> string_buffer_Buf_add(out, ast_VarDeclKind__name[k]); +10809a10798,10844 +> static void ast_VarDeclList_init(ast_VarDeclList* l) +> { +> l->count = 0; +> l->capacity = 4; +> l->data = l->stash; +> } +> +> static void ast_VarDeclList_free(ast_VarDeclList* l) +> { +> if (l->capacity > 4) free(l->data); +> l->data = NULL; +> l->count = 0; +> l->capacity = 0; +> } +> +> static void ast_VarDeclList_resize(ast_VarDeclList* l) +> { +> if (l->capacity < 4) { +> l->capacity = 4; +> l->data = l->stash; +> } else if (l->capacity == 4) { +> l->capacity = l->capacity * 2; +> l->data = malloc(l->capacity * 4); +> memcpy(l->data, l->stash, 4 * 4); +> } else { +> l->capacity = l->capacity * 2; +> l->data = realloc(l->data, l->capacity * 4); +> } +> } +> +> static void ast_VarDeclList_add(ast_VarDeclList* l, ast_VarDecl* d) +> { +> if (l->count >= l->capacity) ast_VarDeclList_resize(l); +> l->data[l->count] = d; +> l->count++; +> } +> +> static u32 ast_VarDeclList_size(const ast_VarDeclList* l) +> { +> return l->count; +> } +> +> static ast_VarDecl** ast_VarDeclList_getData(const ast_VarDeclList* l) +> { +> return l->data; +> } +> +10946c10981 +< string_buffer_Buf_add(out, ast_stmtKind_names[ast_Stmt_getKind(s)]); +--- +> string_buffer_Buf_add(out, ast_StmtKind__name[ast_Stmt_getKind(s)]); +10951,10954c10986,10989 +< u32 size = 24; +< size += (ast_ExprList_size(constraints) * 8); +< size += (ast_ExprList_size(exprs) * 8); +< size += (ast_ExprList_size(clobbers) * 8); +--- +> u32 size = 20; +> size += (ast_ExprList_size(constraints) * 4); +> size += (ast_ExprList_size(exprs) * 4); +> size += (ast_ExprList_size(clobbers) * 4); +10968c11003 +< u32 sz = s->num_constraints * 8; +--- +> u32 sz = s->num_constraints * 4; +10973c11008 +< u32 sz = s->num_exprs * 8; +--- +> u32 sz = s->num_exprs * 4; +10978c11013 +< u32 sz = s->num_clobbers * 8; +--- +> u32 sz = s->num_clobbers * 4; +11032c11067 +< tail += s->num_constraints * 8; +--- +> tail += s->num_constraints * 4; +11039,11040c11074,11075 +< tail += s->num_constraints * 8; +< tail += s->num_exprs * 8; +--- +> tail += s->num_constraints * 4; +> tail += s->num_exprs * 4; +11047,11049c11082,11084 +< tail += s->num_constraints * 8; +< tail += s->num_exprs * 8; +< tail += s->num_clobbers * 8; +--- +> tail += s->num_constraints * 4; +> tail += s->num_exprs * 4; +> tail += s->num_clobbers * 4; +11117c11152 +< ast_AssertStmt* s = ast_context_Context_alloc(c, 24); +--- +> ast_AssertStmt* s = ast_context_Context_alloc(c, 16); +11157c11192 +< static ast_BreakStmt* ast_BreakStmt_create(ast_context_Context* c, src_loc_SrcLoc loc) +--- +> static ast_BreakStmt* ast_BreakStmt_create(ast_context_Context* c, src_loc_SrcLoc loc, u32 name_idx) +11159c11194,11196 +< ast_BreakStmt* s = ast_context_Context_alloc(c, 8); +--- +> u32 size = 8; +> if (name_idx) size += 4; +> ast_BreakStmt* s = ast_context_Context_alloc(c, size); +11160a11198,11201 +> if (name_idx) { +> s->base.breakStmtBits.has_name = true; +> s->name_idx[0] = name_idx; +> } +11163a11205,11215 +> static bool ast_BreakStmt_hasName(const ast_BreakStmt* s) +> { +> return s->base.breakStmtBits.has_name; +> } +> +> static u32 ast_BreakStmt_getName(const ast_BreakStmt* s) +> { +> if (s->base.breakStmtBits.has_name) return s->name_idx[0]; +> return 0; +> } +> +11166a11219 +> if (ast_BreakStmt_hasName(s)) string_buffer_Buf_print(out, " %s", ast_idx2name(s->name_idx[0])); +11173c11226 +< u32 size = 8 + count * 8; +--- +> u32 size = 8 + count * 4; +11178c11231 +< memcpy(s->stmts, stmts, count * 8); +--- +> memcpy(s->stmts, stmts, count * 4); +11186c11239 +< u32 size = 8 + count * 8; +--- +> u32 size = 8 + count * 4; +11221c11274 +< static ast_ContinueStmt* ast_ContinueStmt_create(ast_context_Context* c, src_loc_SrcLoc loc) +--- +> static ast_ContinueStmt* ast_ContinueStmt_create(ast_context_Context* c, src_loc_SrcLoc loc, u32 name_idx) +11223c11276,11278 +< ast_ContinueStmt* s = ast_context_Context_alloc(c, 8); +--- +> u32 size = 8; +> if (name_idx) size += 4; +> ast_ContinueStmt* s = ast_context_Context_alloc(c, size); +11224a11280,11283 +> if (name_idx) { +> s->base.breakStmtBits.has_name = true; +> s->name_idx[0] = name_idx; +> } +11227a11287,11297 +> static bool ast_ContinueStmt_hasName(const ast_ContinueStmt* s) +> { +> return s->base.continueStmtBits.has_name; +> } +> +> static u32 ast_ContinueStmt_getName(const ast_ContinueStmt* s) +> { +> if (s->base.continueStmtBits.has_name) return s->name_idx[0]; +> return 0; +> } +> +11230a11301 +> if (ast_ContinueStmt_hasName(s)) string_buffer_Buf_print(out, " %s", ast_idx2name(s->name_idx[0])); +11249c11320 +< ast_ForStmt* s = ast_context_Context_alloc(c, 40); +--- +> ast_ForStmt* s = ast_context_Context_alloc(c, 24); +11325,11329d11395 +< static const char* ast_GotoStmt_getName(const ast_GotoStmt* g) +< { +< return ast_idx2name(g->name); +< } +< +11342c11408 +< static ast_IfStmt* ast_IfStmt_create(ast_context_Context* c, src_loc_SrcLoc loc, ast_Stmt* cond, ast_Stmt* then, ast_Stmt* else_stmt) +--- +> static ast_IfStmt* ast_IfStmt_create(ast_context_Context* c, src_loc_SrcLoc loc, ast_Stmt* decl, ast_Expr* cond, ast_Stmt* then, ast_Stmt* else_stmt) +11344,11345c11410,11412 +< u32 size = 24; +< if (else_stmt) size += 8; +--- +> u32 has_decl = (decl != NULL); +> u32 has_else = (else_stmt != NULL); +> u32 size = 16 + (has_decl + has_else) * 4; +11347a11415 +> s->base.ifStmtBits.has_source_cond = (cond != NULL); +11350c11418 +< if (else_stmt) { +--- +> if (has_else) { +11352c11420,11424 +< s->else_stmt[0] = else_stmt; +--- +> s->tail[0] = else_stmt; +> } +> if (has_decl) { +> s->base.ifStmtBits.has_decl = 1; +> s->tail[has_else] = decl; +11359c11431,11432 +< ast_Stmt* cond2 = ast_Stmt_instantiate(s->cond, inst); +--- +> ast_Expr* cond2 = NULL; +> if (s->base.ifStmtBits.has_source_cond) cond2 = ast_Expr_instantiate(s->cond, inst); +11362,11363c11435,11438 +< if (s->base.ifStmtBits.has_else) else2 = ast_Stmt_instantiate(s->else_stmt[0], inst); +< return (ast_Stmt*)ast_IfStmt_create(inst->c, s->base.loc, cond2, then2, else2); +--- +> if (s->base.ifStmtBits.has_else) else2 = ast_Stmt_instantiate(ast_IfStmt_getElse(s), inst); +> ast_Stmt* decl2 = NULL; +> if (s->base.ifStmtBits.has_decl) else2 = ast_Stmt_instantiate(ast_IfStmt_getDecl(s), inst); +> return (ast_Stmt*)ast_IfStmt_create(inst->c, s->base.loc, decl2, cond2, then2, else2); +11366c11441,11463 +< static ast_Stmt* ast_IfStmt_getCond(const ast_IfStmt* s) +--- +> static bool ast_IfStmt_hasDecl(const ast_IfStmt* s) +> { +> return s->base.ifStmtBits.has_decl; +> } +> +> static ast_Stmt* ast_IfStmt_getDecl(const ast_IfStmt* s) +> { +> if (!s->base.ifStmtBits.has_decl) return NULL; +> return s->tail[s->base.ifStmtBits.has_else]; +> } +> +> static ast_Stmt** ast_IfStmt_getDecl2(ast_IfStmt* s) +> { +> if (!s->base.ifStmtBits.has_decl) return NULL; +> return &s->tail[s->base.ifStmtBits.has_else]; +> } +> +> static bool ast_IfStmt_hasSourceCond(const ast_IfStmt* s) +> { +> return s->base.ifStmtBits.has_source_cond; +> } +> +> static ast_Expr* ast_IfStmt_getCond(const ast_IfStmt* s) +11371c11468 +< static ast_Stmt** ast_IfStmt_getCond2(ast_IfStmt* s) +--- +> static ast_Expr** ast_IfStmt_getCond2(ast_IfStmt* s) +11385a11483,11487 +> static bool ast_IfStmt_hasElse(const ast_IfStmt* s) +> { +> return s->base.ifStmtBits.has_else; +> } +> +11388c11490 +< if (s->base.ifStmtBits.has_else) return s->else_stmt[0]; +--- +> if (s->base.ifStmtBits.has_else) return s->tail[0]; +11394c11496 +< if (s->base.ifStmtBits.has_else) return &s->else_stmt[0]; +--- +> if (s->base.ifStmtBits.has_else) return &s->tail[0]; +11400a11503,11507 +> string_buffer_Buf_color(out, ast_col_Attr); +> if (ast_IfStmt_hasDecl(s)) { +> string_buffer_Buf_add(out, " decl"); +> if (ast_IfStmt_hasSourceCond(s)) string_buffer_Buf_add(out, " ; cond"); +> } +11402c11509,11510 +< ast_Stmt_print(s->cond, out, indent + 1); +--- +> if (ast_IfStmt_hasDecl(s)) ast_Stmt_print(ast_IfStmt_getDecl(s), out, indent + 1); +> ast_Expr_print(s->cond, out, indent + 1); +11404c11512 +< if (s->base.ifStmtBits.has_else) ast_Stmt_print(s->else_stmt[0], out, indent + 1); +--- +> if (ast_IfStmt_hasElse(s)) ast_Stmt_print(ast_IfStmt_getElse(s), out, indent + 1); +11409c11517 +< ast_LabelStmt* s = ast_context_Context_alloc(c, 24); +--- +> ast_LabelStmt* s = ast_context_Context_alloc(c, 16); +11432c11540,11560 +< static const char* ast_LabelStmt_getName(const ast_LabelStmt* s) +--- +> static bool ast_LabelStmt_hasGoto(const ast_LabelStmt* s) +> { +> return s->base.labelStmtBits.has_goto; +> } +> +> static void ast_LabelStmt_setGoto(ast_LabelStmt* s) +> { +> s->base.labelStmtBits.has_goto = true; +> } +> +> static bool ast_LabelStmt_hasBreak(const ast_LabelStmt* s) +> { +> return s->base.labelStmtBits.has_break; +> } +> +> static void ast_LabelStmt_setBreak(ast_LabelStmt* s) +> { +> s->base.labelStmtBits.has_break = true; +> } +> +> static bool ast_LabelStmt_hasContinue(const ast_LabelStmt* s) +11434c11562,11567 +< return ast_idx2name(s->name); +--- +> return s->base.labelStmtBits.has_continue; +> } +> +> static void ast_LabelStmt_setContinue(ast_LabelStmt* s) +> { +> s->base.labelStmtBits.has_continue = true; +11459,11463c11592,11596 +< if (!ast_LabelStmt_isUsed(s)) { +< string_buffer_Buf_space(out); +< string_buffer_Buf_color(out, ast_col_Attr); +< string_buffer_Buf_add(out, "unused"); +< } +--- +> string_buffer_Buf_color(out, ast_col_Attr); +> if (!ast_LabelStmt_isUsed(s)) string_buffer_Buf_add(out, " unused"); +> if (ast_LabelStmt_hasGoto(s)) string_buffer_Buf_add(out, " has_goto"); +> if (ast_LabelStmt_hasBreak(s)) string_buffer_Buf_add(out, " has_break"); +> if (ast_LabelStmt_hasContinue(s)) string_buffer_Buf_add(out, " has_continue"); +11471c11604 +< if (value) size += 8; +--- +> if (value) size += 4; +11512c11645 +< u32 size = 8 + num_conds * 8 + num_stmts * 8; +--- +> u32 size = 8 + num_conds * 4 + num_stmts * 4; +11519c11652 +< memcpy(s->conds, conds, num_conds * 8); +--- +> memcpy(s->conds, conds, num_conds * 4); +11521c11654 +< memcpy(dst_stmts, stmts, num_stmts * 8); +--- +> memcpy(dst_stmts, stmts, num_stmts * 4); +11529c11662 +< u32 size = 8 + num_conds * 8 + num_stmts * 8; +--- +> u32 size = 8 + num_conds * 4 + num_stmts * 4; +11641c11774 +< u32 size = 16 + has_decl * 8 + numCases * 8; +--- +> u32 size = 12 + has_decl * 4 + numCases * 4; +11647c11780 +< s->base.switchStmtBits.has_cond = cond != NULL; +--- +> s->base.switchStmtBits.has_source_cond = cond != NULL; +11651c11784 +< memcpy(cases_dest, cases, numCases * 8); +--- +> memcpy(cases_dest, cases, numCases * 4); +11659c11792 +< u32 size = 16 + has_decl * 8 + numCases * 8; +--- +> u32 size = 12 + has_decl * 4 + numCases * 4; +11689c11822 +< static bool ast_SwitchStmt_hasCond(const ast_SwitchStmt* s) +--- +> static bool ast_SwitchStmt_hasSourceCond(const ast_SwitchStmt* s) +11691c11824 +< return s->base.switchStmtBits.has_cond; +--- +> return s->base.switchStmtBits.has_source_cond; +11751c11884 +< ast_WhileStmt* s = ast_context_Context_alloc(c, 24); +--- +> ast_WhileStmt* s = ast_context_Context_alloc(c, 16); +12526c12659 +< string_buffer_Buf_add(out, ast_exprKind_names[ast_Expr_getKind(e)]); +--- +> string_buffer_Buf_add(out, ast_ExprKind__name[ast_Expr_getKind(e)]); +12537c12670 +< string_buffer_Buf_add(out, ast_valType_names[ast_Expr_getValType(e)]); +--- +> string_buffer_Buf_add(out, ast_ValType__name[ast_Expr_getValType(e)]); +12542c12675 +< ast_AlternateExpr* e = ast_context_Context_alloc(c, 32); +--- +> ast_AlternateExpr* e = ast_context_Context_alloc(c, 20); +12593c12726 +< u32 size = 32 + (has_expr1 + has_expr2) * 8; +--- +> u32 size = 24 + (has_expr1 + has_expr2) * 4; +12730c12863 +< ast_ArraySubscriptExpr* e = ast_context_Context_alloc(c, 32); +--- +> ast_ArraySubscriptExpr* e = ast_context_Context_alloc(c, 20); +12795,12799d12927 +< static const char* ast_BinaryOpcode_str(ast_BinaryOpcode opcode) +< { +< return ast_binaryOpcode_names[opcode]; +< } +< +12802c12930 +< ast_BinaryOperator* e = ast_context_Context_alloc(c, 32); +--- +> ast_BinaryOperator* e = ast_context_Context_alloc(c, 20); +12842c12970 +< return ast_binaryOpcode_names[ast_BinaryOperator_getOpcode(e)]; +--- +> return ast_BinaryOpcode__name[ast_BinaryOperator_getOpcode(e)]; +12861c12989 +< string_buffer_Buf_add(out, ast_binaryOpcode_names[ast_BinaryOperator_getOpcode(e)]); +--- +> string_buffer_Buf_add(out, ast_BinaryOpcode__name[ast_BinaryOperator_getOpcode(e)]); +12871c12999 +< string_buffer_Buf_add(out, ast_binaryOpcode_names[ast_BinaryOperator_getOpcode(e)]); +--- +> string_buffer_Buf_add(out, ast_BinaryOpcode__name[ast_BinaryOperator_getOpcode(e)]); +12878c13006 +< ast_BitOffsetExpr* e = ast_context_Context_alloc(c, 32); +--- +> ast_BitOffsetExpr* e = ast_context_Context_alloc(c, 20); +12951c13079 +< ast_BooleanLiteral* e = ast_context_Context_alloc(c, 16); +--- +> ast_BooleanLiteral* e = ast_context_Context_alloc(c, 12); +12985c13113 +< const u32 size = 40; +--- +> const u32 size = 24; +12991c13119 +< value_type_Value_setUnsigned(&e->value, 0); +--- +> e->value = 0; +12997c13125 +< const u32 size = 40 + 8; +--- +> const u32 size = 24 + 4; +13003c13131 +< value_type_Value_setUnsigned(&e->value, 0); +--- +> e->value = 0; +13010c13138 +< const u32 size = 40 + 16; +--- +> const u32 size = 24 + 8; +13016c13144 +< value_type_Value_setUnsigned(&e->value, 0); +--- +> e->value = 0; +13027,13028d13154 +< case ast_BuiltinExprKind_EnumMin: +< case ast_BuiltinExprKind_EnumMax: +13043c13169 +< static value_type_Value ast_BuiltinExpr_getValue(const ast_BuiltinExpr* e) +--- +> static u64 ast_BuiltinExpr_useLiteral(const ast_BuiltinExpr* e) +13045c13171 +< return e->value; +--- +> return e->base.base.builtinExprBits.use_literal; +13048c13174 +< static void ast_BuiltinExpr_setValue(ast_BuiltinExpr* e, value_type_Value value) +--- +> static u64 ast_BuiltinExpr_getValue(const ast_BuiltinExpr* e) +13050c13176 +< e->value = value; +--- +> return e->value; +13053c13179 +< static void ast_BuiltinExpr_setUValue(ast_BuiltinExpr* e, u64 val) +--- +> static void ast_BuiltinExpr_setValue(ast_BuiltinExpr* e, u64 val) +13055c13181 +< value_type_Value_setUnsigned(&e->value, val); +--- +> e->value = val; +13097c13223 +< string_buffer_Buf_print(out, " %s", ast_builtin_names[ast_BuiltinExpr_getKind(e)]); +--- +> string_buffer_Buf_print(out, " %s", ast_BuiltinExprKind__name[ast_BuiltinExpr_getKind(e)]); +13099c13225 +< string_buffer_Buf_print(out, " %s", value_type_Value_str(&e->value)); +--- +> string_buffer_Buf_print(out, " %llu", e->value); +13104d13229 +< break; +13107,13110d13231 +< case ast_BuiltinExprKind_EnumMin: +< break; +< case ast_BuiltinExprKind_EnumMax: +< break; +13123c13244 +< string_buffer_Buf_add(out, ast_builtin_names[ast_BuiltinExpr_getKind(e)]); +--- +> string_buffer_Buf_add(out, ast_BuiltinExprKind__name[ast_BuiltinExpr_getKind(e)]); +13129,13130d13249 +< case ast_BuiltinExprKind_EnumMin: +< case ast_BuiltinExprKind_EnumMax: +13148c13267 +< u32 size = 32 + num_args * 8; +--- +> u32 size = 24 + num_args * 4; +13156c13275 +< memcpy(e->args, args, num_args * 8); +--- +> memcpy(e->args, args, num_args * 4); +13162c13281 +< u32 size = 32 + num_args * 8; +--- +> u32 size = 24 + num_args * 4; +13172c13291 +< memcpy(e->args, args, num_args * 8); +--- +> memcpy(e->args, args, num_args * 4); +13182c13301 +< u32 size = 32 + num_args * 8; +--- +> u32 size = 24 + num_args * 4; +13311c13430 +< ast_CharLiteral* e = ast_context_Context_alloc(c, 16); +--- +> ast_CharLiteral* e = ast_context_Context_alloc(c, 12); +13351d13469 +< string_buffer_Buf_add1(out, '\''); +13354d13471 +< string_buffer_Buf_add1(out, '\''); +13362c13479 +< ast_ConditionalOperator* e = ast_context_Context_alloc(c, 48); +--- +> ast_ConditionalOperator* e = ast_context_Context_alloc(c, 28); +13437c13554 +< u32 size = 40 + ast_TypeRefHolder_getExtraSize(ref); +--- +> u32 size = 32 + ast_TypeRefHolder_getExtraSize(ref); +13452c13569 +< u32 size = 40 + extra; +--- +> u32 size = 32 + extra; +13528c13645 +< ast_FieldDesignatedInitExpr* e = ast_context_Context_alloc(c, 40); +--- +> ast_FieldDesignatedInitExpr* e = ast_context_Context_alloc(c, 24); +13649,13671d13765 +< static const char* ast_IdentifierKind_str(ast_IdentifierKind k) +< { +< switch (k) { +< case ast_IdentifierKind_Unresolved: +< return "Unresolved"; +< case ast_IdentifierKind_Module: +< return "Module"; +< case ast_IdentifierKind_Function: +< return "Function"; +< case ast_IdentifierKind_Type: +< return "Type"; +< case ast_IdentifierKind_Var: +< return "Var"; +< case ast_IdentifierKind_EnumConstant: +< return "EnumConstant"; +< case ast_IdentifierKind_StructMember: +< return "StructMember"; +< case ast_IdentifierKind_Label: +< return "Label"; +< } +< return ""; +< } +< +13674c13768 +< ast_IdentifierExpr* e = ast_context_Context_alloc(c, 24); +--- +> ast_IdentifierExpr* e = ast_context_Context_alloc(c, 16); +13749c13843 +< string_buffer_Buf_add(out, ast_IdentifierKind_str(kind)); +--- +> string_buffer_Buf_add(out, ast_IdentifierKind__name[kind]); +13768c13862 +< ast_ImplicitCastExpr* e = ast_context_Context_alloc(c, 24); +--- +> ast_ImplicitCastExpr* e = ast_context_Context_alloc(c, 16); +13833c13927 +< string_buffer_Buf_add(out, ast_implicitCastKind_names[ast_ImplicitCastExpr_getKind(e)]); +--- +> string_buffer_Buf_add(out, ast_ImplicitCastKind__name[ast_ImplicitCastExpr_getKind(e)]); +13840c13934 +< u32 size = 24 + num_values * 8; +--- +> u32 size = 20 + num_values * 4; +13846c13940 +< memcpy(e->values, values, num_values * 8); +--- +> memcpy(e->values, values, num_values * 4); +13854c13948 +< u32 size = 24 + num_values * 8; +--- +> u32 size = 20 + num_values * 4; +14003c14097 +< string_buffer_Buf_print(out, "0x%.*lX", (int)len - 2, value); +--- +> string_buffer_Buf_print(out, "0x%.*llX", (int)len - 2, value); +14020c14114 +< string_buffer_Buf_print(out, "%lu", e->val); +--- +> string_buffer_Buf_print(out, "%llu", e->val); +14040,14062d14133 +< static const char* ast_MemberKind_str(ast_MemberKind k) +< { +< switch (k) { +< case ast_MemberKind_Unresolved: +< return "Unresolved"; +< case ast_MemberKind_Module: +< return "Module"; +< case ast_MemberKind_StructMember: +< return "StructMember"; +< case ast_MemberKind_TypeFunc: +< return "TypeFunc"; +< case ast_MemberKind_StaticTypeFunc: +< return "StaticTypeFunc"; +< case ast_MemberKind_EnumConstant: +< return "EnumConstant"; +< case ast_MemberKind_EnumAssocValue: +< return "EnumAssocValue"; +< case ast_MemberKind_EnumConstantValue: +< return "EnumConstantValue"; +< } +< return ""; +< } +< +14065c14136 +< u32 size = 32; +--- +> u32 size = 20; +14082c14153 +< u32 size = 32; +--- +> u32 size = 20; +14330c14401 +< string_buffer_Buf_add(out, ast_MemberKind_str(kind)); +--- +> string_buffer_Buf_add(out, ast_MemberKind__name[kind]); +14367c14438 +< ast_NamedArgument* e = ast_context_Context_alloc(c, 32); +--- +> ast_NamedArgument* e = ast_context_Context_alloc(c, 24); +14424c14495 +< ast_NilExpr* e = ast_context_Context_alloc(c, 16); +--- +> ast_NilExpr* e = ast_context_Context_alloc(c, 12); +14449c14520 +< ast_ParenExpr* e = ast_context_Context_alloc(c, 24); +--- +> ast_ParenExpr* e = ast_context_Context_alloc(c, 16); +14493c14564 +< ast_RangeExpr* e = ast_context_Context_alloc(c, 32); +--- +> ast_RangeExpr* e = ast_context_Context_alloc(c, 20); +14553c14624 +< ast_StringLiteral* e = ast_context_Context_alloc(c, 24); +--- +> ast_StringLiteral* e = ast_context_Context_alloc(c, 20); +14557c14628 +< e->size = len + 1; +--- +> e->len = len; +14562,14567c14633 +< static const char* ast_StringLiteral_getText(const ast_StringLiteral* e) +< { +< return ast_idx2name(e->value); +< } +< +< static u32 ast_StringLiteral_getTextIndex(const ast_StringLiteral* e) +--- +> static u32 ast_StringLiteral_getText(const ast_StringLiteral* e) +14572c14638 +< static u32 ast_StringLiteral_getSize(const ast_StringLiteral* e) +--- +> static u32 ast_StringLiteral_getLength(const ast_StringLiteral* e) +14574c14640 +< return e->size; +--- +> return e->len; +14584,14586c14650 +< string_buffer_Buf_add1(out, '"'); +< string_buffer_Buf_encodeBytes(out, ast_idx2name(e->value), e->size - 1, '"'); +< string_buffer_Buf_add1(out, '"'); +--- +> string_buffer_Buf_encodeBytes(out, ast_idx2name(e->value), e->len, '"'); +14646c14710 +< ast_UnaryOperator* e = ast_context_Context_alloc(c, 24); +--- +> ast_UnaryOperator* e = ast_context_Context_alloc(c, 16); +14706c14770 +< return ast_unaryOpcode_names[ast_UnaryOperator_getOpcode(e)]; +--- +> return ast_UnaryOpcode__name[ast_UnaryOperator_getOpcode(e)]; +14715c14779 +< string_buffer_Buf_add(out, ast_unaryOpcode_names[ast_UnaryOperator_getOpcode(e)]); +--- +> string_buffer_Buf_add(out, ast_UnaryOpcode__name[ast_UnaryOperator_getOpcode(e)]); +14722c14786 +< const char* opcode = ast_unaryOpcode_names[ast_UnaryOperator_getOpcode(e)]; +--- +> const char* opcode = ast_UnaryOpcode__name[ast_UnaryOperator_getOpcode(e)]; +14735a14800 +> t->typeBits.align = 0; +14744a14810,14814 +> static ast_QualType ast_Type_getCanonicalType(const ast_Type* t) +> { +> return t->canonicalType; +> } +> +14789a14860,14899 +> static void ast_Type_setAlignment(ast_Type* t, u32 align) +> { +> t->typeBits.align = align; +> } +> +> static u32 ast_Type_getAlignment(const ast_Type* t) +> { +> switch (ast_Type_getKind(t)) { +> case ast_TypeKind_Builtin: +> case ast_TypeKind_Pointer: +> case ast_TypeKind_Function: +> return t->typeBits.align; +> case ast_TypeKind_Array: { +> const ast_ArrayType* at = (ast_ArrayType*)t; +> ast_QualType elem = ast_ArrayType_getElemType(at); +> return ast_QualType_getAlignment(elem); +> } +> case ast_TypeKind_Struct: { +> const ast_StructType* s = (ast_StructType*)t; +> const ast_StructTypeDecl* std = ast_StructType_getDecl(s); +> return ast_StructTypeDecl_getAlignment(std); +> } +> case ast_TypeKind_Enum: { +> const ast_EnumType* e = (ast_EnumType*)t; +> const ast_EnumTypeDecl* etd = ast_EnumType_getDecl(e); +> ast_QualType it = ast_EnumTypeDecl_getImplType(etd); +> return ast_Type_getAlignment(ast_QualType_getTypeOrNil(it)); +> } +> case ast_TypeKind_Void: +> return 0; +> case ast_TypeKind_Alias: { +> ast_QualType canon = ast_Type_getCanonicalType(t); +> return ast_QualType_getAlignment(canon); +> } +> case ast_TypeKind_Module: +> return 0; +> } +> return 0; +> } +> +14871c14981 +< ast_AliasType* t = ast_context_Context_alloc(c, 24); +--- +> ast_AliasType* t = ast_context_Context_alloc(c, 16); +14898c15008 +< u32 size = 32 + is_enum_index * 8; +--- +> u32 size = 20 + is_enum_index * 4; +14914c15024 +< ast_ArrayType* t = ast_context_Context_alloc(c, 32); +--- +> ast_ArrayType* t = ast_context_Context_alloc(c, 20); +14989,14993d15098 +< static const char* ast_BuiltinKind_str(ast_BuiltinKind kind) +< { +< return ast_builtinType_names[kind]; +< } +< +14996c15101,15104 +< ast_BuiltinType* b = ast_context_Context_alloc(c, 16); +--- +> ast_BuiltinKind base_kind = kind; +> if (kind == ast_BuiltinKind_ISize) base_kind = (ast_context_Context_getPointerSize(c) == 4) ? ast_BuiltinKind_Int32 : ast_BuiltinKind_Int64; +> if (kind == ast_BuiltinKind_USize) base_kind = (ast_context_Context_getPointerSize(c) == 4) ? ast_BuiltinKind_UInt32 : ast_BuiltinKind_UInt64; +> ast_BuiltinType* b = ast_context_Context_alloc(c, 12); +14998a15107,15109 +> b->base.builtinTypeBits.base_kind = base_kind; +> b->base.builtinTypeBits.width = ast_BuiltinKind__width[base_kind]; +> ast_Type_setAlignment(&b->base, ast_BuiltinKind__align[base_kind]); +15010,15015c15121 +< return ast_globals->builtinType_baseTypes[ast_BuiltinType_getKind(b)]; +< } +< +< static ast_BuiltinKind ast_BuiltinType_getBuiltinKind(const ast_BuiltinType* b) +< { +< return b->base.builtinTypeBits.kind; +--- +> return b->base.builtinTypeBits.base_kind; +15020c15126 +< return ast_BuiltinType_getBuiltinKind(b) == ast_BuiltinKind_Int32; +--- +> return ast_BuiltinType_getKind(b) == ast_BuiltinKind_Int32; +15025,15030c15131 +< return ast_BuiltinType_getBuiltinKind(b) == ast_BuiltinKind_Bool; +< } +< +< static const char* ast_BuiltinType_kind2str(const ast_BuiltinType* b) +< { +< return ast_builtinType_names[ast_BuiltinType_getKind(b)]; +--- +> return ast_BuiltinType_getKind(b) == ast_BuiltinKind_Bool; +15035c15136 +< return ast_BuiltinType_promotable[ast_BuiltinType_getKind(b)]; +--- +> return ast_BuiltinKind__promotable[ast_BuiltinType_getKind(b)]; +15040c15141 +< return ast_BuiltinType_integer[ast_BuiltinType_getKind(b)]; +--- +> return ast_BuiltinKind__is_integer[ast_BuiltinType_getKind(b)]; +15055c15156 +< return ast_BuiltinType_signed[ast_BuiltinType_getKind(b)]; +--- +> return ast_BuiltinKind__is_signed[ast_BuiltinType_getKind(b)]; +15060c15161 +< return ast_BuiltinType_unsigned[ast_BuiltinType_getKind(b)]; +--- +> return ast_BuiltinKind__is_unsigned[ast_BuiltinType_getKind(b)]; +15065c15166 +< return ast_globals->builtinType_sizes[ast_BuiltinType_getKind(b)]; +--- +> return b->base.typeBits.align; +15070c15171 +< return ast_globals->builtinType_width[ast_BuiltinType_getKind(b)]; +--- +> return b->base.builtinTypeBits.width; +15075c15176 +< string_buffer_Buf_add(out, ast_builtinType_names[ast_BuiltinType_getKind(b)]); +--- +> string_buffer_Buf_add(out, ast_BuiltinKind__name[ast_BuiltinType_getKind(b)]); +15081c15182 +< string_buffer_Buf_print(out, "BuiltinType [%p] %s\n", t, ast_BuiltinType_kind2str(t)); +--- +> string_buffer_Buf_print(out, "BuiltinType [%p] %s\n", t, ast_BuiltinKind__name[ast_BuiltinType_getKind(t)]); +15086c15187 +< ast_EnumType* t = ast_context_Context_alloc(c, 24); +--- +> ast_EnumType* t = ast_context_Context_alloc(c, 16); +15103,15107d15203 +< static const char* ast_EnumType_getName(const ast_EnumType* t) +< { +< return ast_Decl_getName(&t->decl->base); +< } +< +15123c15219 +< ast_FunctionType* t = ast_context_Context_alloc(c, 24); +--- +> ast_FunctionType* t = ast_context_Context_alloc(c, 16); +15124a15221 +> ast_Type_setAlignment(&t->base, ast_context_Context_getPointerSize(c)); +15153c15250 +< ast_ModuleType* t = ast_context_Context_alloc(c, 24); +--- +> ast_ModuleType* t = ast_context_Context_alloc(c, 16); +15178c15275 +< ast_PointerType* t = ast_context_Context_alloc(c, 24); +--- +> ast_PointerType* t = ast_context_Context_alloc(c, 16); +15179a15277 +> ast_Type_setAlignment(&t->base, ast_context_Context_getPointerSize(c)); +15396a15495,15500 +> static u32 ast_QualType_getAlignment(const ast_QualType qt) +> { +> const ast_Type* t = ast_QualType_getType(qt); +> return ast_Type_getAlignment(t); +> } +> +15635a15740,15780 +> static void ast_QualType_setTypeUsedPublic(ast_QualType qt) +> { +> const ast_Type* t = ast_QualType_getType(qt); +> ast_Decl* d = NULL; +> switch (ast_Type_getKind(t)) { +> case ast_TypeKind_Builtin: +> case ast_TypeKind_Void: +> return; +> case ast_TypeKind_Pointer: { +> ast_PointerType* pt = (ast_PointerType*)t; +> ast_QualType_setTypeUsedPublic(pt->inner); +> return; +> } +> case ast_TypeKind_Array: { +> ast_ArrayType* at = (ast_ArrayType*)t; +> ast_QualType_setTypeUsedPublic(at->elem); +> return; +> } +> case ast_TypeKind_Struct: { +> ast_StructType* st = (ast_StructType*)t; +> d = (ast_Decl*)st->decl; +> break; +> } +> case ast_TypeKind_Enum: { +> ast_EnumType* et = (ast_EnumType*)t; +> d = (ast_Decl*)et->decl; +> break; +> } +> case ast_TypeKind_Function: +> return; +> case ast_TypeKind_Alias: { +> ast_AliasType* at = (ast_AliasType*)t; +> d = (ast_Decl*)at->decl; +> break; +> } +> case ast_TypeKind_Module: +> return; +> } +> if (d) ast_Decl_setUsedPublic(d); +> } +> +15732c15877 +< ast_StructType* t = ast_context_Context_alloc(c, 24); +--- +> ast_StructType* t = ast_context_Context_alloc(c, 16); +15765c15910 +< static const char* ast_Ref_getName(const ast_Ref* r) +--- +> static u32 ast_Ref_getNameIdx(const ast_Ref* r) +15767c15912 +< return ast_idx2name(r->name_idx); +--- +> return r->name_idx; +15776a15922,15927 +> static void ast_TypeRefHolder_copy(ast_TypeRefHolder* h, const ast_TypeRef* ref) +> { +> u32 size = 8 + ast_TypeRef_getExtraSize(ref); +> memcpy(&h->ref, ref, size); +> } +> +15967,15968c16118,16119 +< u32 extra = numrefs * 16; +< extra += r->flags.num_arrays * 8; +--- +> u32 extra = numrefs * 12; +> extra += r->flags.num_arrays * 4; +16119c16270 +< const u8* ptr = (u8*)r->refs + numrefs * 16; +--- +> const u8* ptr = (u8*)r->refs + numrefs * 12; +16127c16278 +< const u8* ptr = (u8*)r->refs + numrefs * 16; +--- +> const u8* ptr = (u8*)r->refs + numrefs * 12; +16135c16286 +< const u8* ptr = (u8*)r->refs + numrefs * 16; +--- +> const u8* ptr = (u8*)r->refs + numrefs * 12; +16147c16298 +< string_buffer_Buf_add(out, ast_builtinType_names[ast_TypeRef_getBuiltinKind(r)]); +--- +> string_buffer_Buf_add(out, ast_BuiltinKind__name[ast_TypeRef_getBuiltinKind(r)]); +16188c16339 +< string_buffer_Buf_add(out, ast_builtinType_names[ast_TypeRef_getBuiltinKind(r)]); +--- +> string_buffer_Buf_add(out, ast_BuiltinKind__name[ast_TypeRef_getBuiltinKind(r)]); +16234c16385 +< ast_VoidType* b = ast_context_Context_alloc(c, 16); +--- +> ast_VoidType* b = ast_context_Context_alloc(c, 12); +16257c16408 +< l->values = malloc(l->capacity * 8); +--- +> l->values = malloc(l->capacity * 4); +16270c16421 +< void* values2 = malloc(l->capacity * 8); +--- +> void* values2 = malloc(l->capacity * 4); +16273c16424 +< memcpy(values2, old, l->count * 8); +--- +> memcpy(values2, old, l->count * 4); +16294c16445 +< ast_AST* a = calloc(1, 208); +--- +> ast_AST* a = calloc(1, 132); +16298c16449 +< a->idx = ast_addAST(a); +--- +> a->idx = ast_Globals_addAST(ast_globals, a); +16332,16336d16482 +< static const char* ast_AST_getName(const ast_AST* a) +< { +< return ast_Module_getName(a->mod); +< } +< +16559c16705 +< l->decls = l->stash; +--- +> l->data = l->stash; +16564c16710,16711 +< if (l->capacity > 4) free(l->decls); +--- +> if (l->capacity > 4) free(l->data); +> l->data = NULL; +16569c16716 +< static void ast_DeclList_add(ast_DeclList* l, ast_Decl* d) +--- +> static void ast_DeclList_clear(ast_DeclList* l) +16571,16582c16718,16732 +< if (l->count >= l->capacity) { +< if (l->capacity == 0) { +< l->capacity = 4; +< l->decls = l->stash; +< } else { +< u32 capacity2 = l->capacity + l->capacity / 2 + 2; +< void* decls2 = malloc(capacity2 * 8); +< memcpy(decls2, l->decls, l->count * 8); +< if (l->capacity > 4) free(l->decls); +< l->capacity = capacity2; +< l->decls = decls2; +< } +--- +> l->count = 0; +> } +> +> static void ast_DeclList_resize(ast_DeclList* l) +> { +> if (l->capacity < 4) { +> l->capacity = 4; +> l->data = l->stash; +> } else if (l->capacity == 4) { +> l->capacity = l->capacity * 2; +> l->data = malloc(l->capacity * 4); +> memcpy(l->data, l->stash, 4 * 4); +> } else { +> l->capacity = l->capacity * 2; +> l->data = realloc(l->data, l->capacity * 4); +16584,16585d16733 +< l->decls[l->count] = d; +< l->count++; +16588c16736 +< static void ast_DeclList_clear(ast_DeclList* l) +--- +> static void ast_DeclList_add(ast_DeclList* l, ast_Decl* d) +16590c16738,16740 +< l->count = 0; +--- +> if (l->count >= l->capacity) ast_DeclList_resize(l); +> l->data[l->count] = d; +> l->count++; +16600c16750 +< return l->decls[idx]; +--- +> return l->data[idx]; +16603c16753 +< static ast_Decl** ast_DeclList_getDecls(const ast_DeclList* l) +--- +> static ast_Decl** ast_DeclList_getData(const ast_DeclList* l) +16605c16755 +< return l->decls; +--- +> return l->data; +16630,16631c16780,16781 +< void* exprs2 = malloc(capacity2 * 8); +< memcpy(exprs2, l->exprs, l->count * 8); +--- +> void* exprs2 = malloc(capacity2 * 4); +> memcpy(exprs2, l->exprs, l->count * 4); +16653c16803 +< memset(l, 0, 16); +--- +> memset(l, 0, 12); +16665c16815 +< void* decls2 = malloc(l->capacity * 8); +--- +> void* decls2 = malloc(l->capacity * 4); +16668c16818 +< memcpy(decls2, old, l->count * 8); +--- +> memcpy(decls2, old, l->count * 4); +16703c16853 +< memset(l, 0, 16); +--- +> memset(l, 0, 12); +16715c16865 +< void* decls2 = malloc(l->capacity * 8); +--- +> void* decls2 = malloc(l->capacity * 4); +16718c16868 +< memcpy(decls2, old, l->count * 8); +--- +> memcpy(decls2, old, l->count * 4); +16767c16917 +< ast_TemplateInstance* inst2 = malloc(capacity * 16); +--- +> ast_TemplateInstance* inst2 = malloc(capacity * 8); +16769c16919 +< memcpy(inst2, f->instances, f->count * 16); +--- +> memcpy(inst2, f->instances, f->count * 8); +16818c16968 +< ast_TemplateFunction* funcs2 = malloc(capacity * 24); +--- +> ast_TemplateFunction* funcs2 = malloc(capacity * 12); +16820c16970 +< memcpy(funcs2, t->funcs, t->count * 24); +--- +> memcpy(funcs2, t->funcs, t->count * 12); +16871c17021 +< ast_Module* m = calloc(1, 80); +--- +> ast_Module* m = calloc(1, 56); +17060c17210 +< void* buf = malloc(m->max_files * 8); +--- +> void* buf = malloc(m->max_files * 4); +17063c17213 +< memcpy(buf, old, m->num_files * 8); +--- +> memcpy(buf, old, m->num_files * 4); +17123a17274 +> p->context = c; +17127d17277 +< p->context = c; +17128a17279 +> memset(p->slots, 0, 16); +17142c17293 +< ast_PointerPoolSlot* slots2 = malloc(p->capacity * 32); +--- +> ast_PointerPoolSlot* slots2 = malloc(p->capacity * 16); +17144c17295 +< memcpy(slots2, p->slots, p->count * 32); +--- +> memcpy(slots2, p->slots, p->count * 16); +17160c17311 +< memset(slot, 0, 32); +--- +> memset(slot, 0, 16); +17171a17323,17327 +> static void ast_PointerPool_report(const ast_PointerPool* p) +> { +> printf("pointer_pool: %u/%u, %u bytes\n", p->count, p->capacity, 16 + p->capacity * 16); +> } +> +17178c17334 +< l->asserts = malloc(l->capacity * 8); +--- +> l->asserts = malloc(l->capacity * 4); +17191c17347 +< void* asserts2 = malloc(l->capacity * 8); +--- +> void* asserts2 = malloc(l->capacity * 4); +17194c17350 +< memcpy(asserts2, old, l->count * 8); +--- +> memcpy(asserts2, old, l->count * 4); +17238c17394 +< ast_StringTypeSlot* slots2 = malloc(p->capacity * 16); +--- +> ast_StringTypeSlot* slots2 = malloc(p->capacity * 8); +17240c17396 +< memcpy(slots2, p->slots, p->count * 16); +--- +> memcpy(slots2, p->slots, p->count * 8); +17267a17424,17428 +> static void ast_StringTypePool_report(const ast_StringTypePool* p) +> { +> printf("string_pool: %u/%u, %u bytes\n", p->count, p->capacity, 16 + p->capacity * 8); +> } +> +17295c17456 +< ast_Decl** decls = malloc(capacity * 8); +--- +> ast_Decl** decls = malloc(capacity * 4); +17300c17461 +< memcpy(decls, t->decls, count * 8); +--- +> memcpy(decls, t->decls, count * 4); +17389c17550 +< static void ast_initialize(ast_context_Context* c, string_pool_Pool* astPool, u32 wordsize, bool use_color) +--- +> static void ast_initialize(ast_context_Context* c, string_pool_Pool* astPool, bool use_color) +17391,17436c17552,17591 +< ast_globals = malloc(344); +< ast_PointerPool_init(&ast_globals->pointers, c); +< ast_StringTypePool_init(&ast_globals->string_types, c); +< ast_globals->wordsize = wordsize; +< ast_globals->use_color = use_color; +< ast_globals->names_pool = astPool; +< ast_globals->ast_count = 1; +< ast_globals->ast_capacity = 0; +< ast_globals->ast_list = NULL; +< ast_globals->dump_buf = string_buffer_create(4096, use_color, 2); +< for (ast_BuiltinKind kind = ast_BuiltinKind_Char; kind <= ast_BuiltinKind_Bool; kind++) { +< ast_QualType_set(&ast_globals->builtins[kind], (ast_Type*)ast_BuiltinType_create(c, kind)); +< } +< ast_QualType_set(&ast_globals->void_type, (ast_Type*)ast_VoidType_create(c)); +< ast_Type* void_ptr = ast_getPointerType(ast_globals->void_type); +< ast_QualType_set(&ast_globals->void_ptr_type, void_ptr); +< ast_Type_setCanonicalType(void_ptr, ast_globals->void_ptr_type); +< memcpy(ast_globals->builtinType_sizes, ast_BuiltinType_default_sizes, 56); +< ast_globals->builtinType_sizes[ast_BuiltinKind_ISize] = wordsize; +< ast_globals->builtinType_sizes[ast_BuiltinKind_USize] = wordsize; +< memcpy(ast_globals->builtinType_width, ast_BuiltinType_default_widths, 56); +< ast_globals->builtinType_width[ast_BuiltinKind_ISize] = wordsize * 8; +< ast_globals->builtinType_width[ast_BuiltinKind_USize] = wordsize * 8; +< for (ast_BuiltinKind kind = ast_BuiltinKind_Char; kind <= ast_BuiltinKind_Bool; kind++) { +< ast_globals->builtinType_baseTypes[kind] = kind; +< } +< if (wordsize == 4) { +< ast_globals->builtinType_baseTypes[ast_BuiltinKind_ISize] = ast_BuiltinKind_Int32; +< ast_globals->builtinType_baseTypes[ast_BuiltinKind_USize] = ast_BuiltinKind_UInt32; +< } else { +< ast_globals->builtinType_baseTypes[ast_BuiltinKind_ISize] = ast_BuiltinKind_Int64; +< ast_globals->builtinType_baseTypes[ast_BuiltinKind_USize] = ast_BuiltinKind_UInt64; +< } +< } +< +< static void ast_deinit(bool print_stats) +< { +< ast_globals->names_pool = NULL; +< ast_globals->ast_count = 0; +< ast_globals->ast_capacity = 0; +< free(ast_globals->ast_list); +< ast_globals->ast_list = NULL; +< ast_PointerPool_clear(&ast_globals->pointers); +< ast_StringTypePool_clear(&ast_globals->string_types); +< string_buffer_Buf_free(ast_globals->dump_buf); +< free(ast_globals); +--- +> ast_Globals* g = calloc(120, 1); +> ast_PointerPool_init(&g->pointers, c); +> ast_StringTypePool_init(&g->string_types, c); +> g->use_color = use_color; +> g->names_pool = astPool; +> g->ast_count = 0; +> g->ast_capacity = 0; +> g->ast_list = NULL; +> g->dump_buf = string_buffer_create(4096, use_color, 2); +> ast_globals = g; +> ast_Globals_addAST(g, NULL); +> for (ast_BuiltinKind kind = ast_BuiltinKind_Bool; kind <= ast_BuiltinKind_USize; kind++) { +> ast_QualType_set(&g->builtins[kind], (ast_Type*)ast_BuiltinType_create(c, kind)); +> } +> ast_QualType_set(&g->void_type, (ast_Type*)ast_VoidType_create(c)); +> ast_Type* void_ptr = ast_PointerPool_getPointer(&g->pointers, g->void_type); +> ast_QualType_set(&g->void_ptr_type, void_ptr); +> ast_Type_setCanonicalType(void_ptr, g->void_ptr_type); +> } +> +> static void ast_report(void) +> { +> ast_Globals* g = ast_globals; +> printf("ast_list: %u/%u, %u bytes\n", g->ast_count, g->ast_capacity, g->ast_capacity * 4); +> ast_StringTypePool_report(&g->string_types); +> ast_PointerPool_report(&g->pointers); +> } +> +> static void ast_deinit(void) +> { +> ast_Globals* g = ast_globals; +> g->names_pool = NULL; +> g->ast_count = 0; +> g->ast_capacity = 0; +> free(g->ast_list); +> g->ast_list = NULL; +> ast_PointerPool_clear(&g->pointers); +> ast_StringTypePool_clear(&g->string_types); +> string_buffer_Buf_free(g->dump_buf); +> free(g); +17440,17444d17594 +< static u32 ast_getWordSize(void) +< { +< return ast_globals->wordsize; +< } +< +17476c17626 +< static u32 ast_addAST(ast_AST* ast_) +--- +> static u32 ast_Globals_addAST(ast_Globals* g, ast_AST* a) +17478,17484c17628,17634 +< if (ast_globals->ast_count >= ast_globals->ast_capacity) { +< if (ast_globals->ast_capacity == 0) ast_globals->ast_capacity = 16; +< else ast_globals->ast_capacity *= 2; +< void* buf = malloc(ast_globals->ast_capacity * 8); +< if (ast_globals->ast_list) { +< void* old = ast_globals->ast_list; +< memcpy(buf, old, ast_globals->ast_count * 8); +--- +> if (g->ast_count >= g->ast_capacity) { +> if (g->ast_capacity == 0) g->ast_capacity = 16; +> else g->ast_capacity *= 2; +> void* buf = malloc(g->ast_capacity * 4); +> if (g->ast_list) { +> void* old = g->ast_list; +> memcpy(buf, old, g->ast_count * 4); +17487c17637 +< ast_globals->ast_list = buf; +--- +> g->ast_list = buf; +17489,17491c17639,17641 +< u32 idx = ast_globals->ast_count; +< ast_globals->ast_list[idx] = ast_; +< ast_globals->ast_count++; +--- +> u32 idx = g->ast_count; +> g->ast_list[idx] = a; +> g->ast_count++; +17495c17645 +< static ast_AST* ast_idx2ast(u32 idx) +--- +> static ast_AST* ast_Globals_idx2ast(ast_Globals* g, u32 idx) +17497,17498c17647 +< if (idx == 0) return NULL; +< return ast_globals->ast_list[idx]; +--- +> return g->ast_list[idx]; +17513,17558d17661 +< static void ast_setTypePublicUsed(ast_QualType qt) +< { +< const ast_Type* t = ast_QualType_getType(qt); +< ast_Decl* d = NULL; +< switch (ast_Type_getKind(t)) { +< case ast_TypeKind_Builtin: +< case ast_TypeKind_Void: +< return; +< case ast_TypeKind_Pointer: { +< ast_PointerType* pt = (ast_PointerType*)t; +< ast_setTypePublicUsed(pt->inner); +< return; +< } +< case ast_TypeKind_Array: { +< ast_ArrayType* at = (ast_ArrayType*)t; +< ast_setTypePublicUsed(at->elem); +< return; +< } +< case ast_TypeKind_Struct: { +< ast_StructType* st = (ast_StructType*)t; +< d = (ast_Decl*)st->decl; +< break; +< } +< case ast_TypeKind_Enum: { +< ast_EnumType* et = (ast_EnumType*)t; +< d = (ast_Decl*)et->decl; +< break; +< } +< case ast_TypeKind_Function: +< return; +< case ast_TypeKind_Alias: { +< ast_AliasType* at = (ast_AliasType*)t; +< d = (ast_Decl*)at->decl; +< break; +< } +< case ast_TypeKind_Module: +< return; +< } +< if (d) ast_Decl_setUsedPublic(d); +< } +< +< static ast_BuiltinKind ast_getNativeKind(void) +< { +< return ast_globals->wordsize == 8 ? ast_BuiltinKind_UInt64 : ast_BuiltinKind_UInt32; +< } +< +17611c17714 +< return ast_BuiltinExpr_getValue(bi); +--- +> return value_type_Value_createUnsigned(ast_BuiltinExpr_getValue(bi)); +17971c18074 +< const char* cname = ast_FunctionDecl_getCName(fd); +--- +> u32 cname = ast_FunctionDecl_getCName(fd); +17973c18076 +< fun.address = dlsym(dlfcn_RTLD_DEFAULT, cname); +--- +> fun.address = dlsym(dlfcn_RTLD_DEFAULT, ast_idx2name(cname)); +18007c18110 +< fprintf(stderr, "unsupported function prototype: %s\n", ast_FunctionDecl_getCName(fd)); +--- +> fprintf(stderr, "unsupported function prototype: %s\n", ast_idx2name(ast_FunctionDecl_getCName(fd))); +18104c18207,18211 +< ast_Cont cont = ast_Stmt_eval(ast_IfStmt_getCond(s), sf); +--- +> if (ast_IfStmt_hasDecl(s)) { +> ast_Cont cont = ast_Stmt_eval(ast_IfStmt_getDecl(s), sf); +> if (cont != ast_Cont_Normal) return cont; +> } +> ast_Cont cont = ast_Expr_eval(ast_IfStmt_getCond(s), sf); +18344c18451 +< string_list_List features; +--- +> string_map_Map features; +18366c18473 +< static const string_list_List* build_target_Target_getFeatures(const build_target_Target* t); +--- +> static const string_map_Map* build_target_Target_getFeatures(const build_target_Target* t); +18430c18537 +< memset(l, 0, 16); +--- +> memset(l, 0, 12); +18468c18575 +< build_target_Target* t = calloc(1, 144); +--- +> build_target_Target* t = calloc(1, 116); +18472c18579 +< string_list_List_init(&t->features, pool); +--- +> string_map_Map_init(&t->features, pool); +18485c18592 +< string_list_List_free(&t->features); +--- +> string_map_Map_free(&t->features); +18511c18618 +< static const string_list_List* build_target_Target_getFeatures(const build_target_Target* t) +--- +> static const string_map_Map* build_target_Target_getFeatures(const build_target_Target* t) +18518c18625 +< string_list_List_add(&t->features, feature); +--- +> string_map_Map_addNameValue(&t->features, feature, "1"); +18523c18630 +< string_list_List_del(&t->features, feature); +--- +> string_map_Map_del(&t->features, feature); +18713c18820 +< memset(l, 0, 16); +--- +> memset(l, 0, 12); +18777,18778c18884,18885 +< static const char* diagnostics_category_names[3] = { "note", "warning", "error" }; +< static color_Color diagnostics_category_colors[3] = { +--- +> static const char* const diagnostics_Category__name[3] = { "note", "warning", "error" }; +> static const color_Color diagnostics_Category__color[3] = { +18806c18913 +< diagnostics_Diags* diags = calloc(1, 40); +--- +> diagnostics_Diags* diags = calloc(1, 24); +18921,18922c19028,19029 +< string_buffer_Buf_color(out, diagnostics_category_colors[category]); +< string_buffer_Buf_add(out, diagnostics_category_names[category]); +--- +> string_buffer_Buf_color(out, diagnostics_Category__color[category]); +> string_buffer_Buf_add(out, diagnostics_Category__name[category]); +19040c19147 +< memset(l, 0, 24); +--- +> memset(l, 0, 16); +19087c19194 +< memcpy(&list->mods[list->num_mods], other->mods, other->num_mods * 8); +--- +> memcpy(&list->mods[list->num_mods], other->mods, other->num_mods * 4); +19137c19244 +< void* buf = malloc(l->max_mods * 8); +--- +> void* buf = malloc(l->max_mods * 4); +19140c19247 +< memcpy(buf, old, l->num_mods * 8); +--- +> memcpy(buf, old, l->num_mods * 4); +19270c19377 +< memset(l, 0, 48); +--- +> memset(l, 0, 28); +19279,19280c19386,19387 +< ast_SwitchCase** heap2 = malloc(l->capacity * 8); +< memcpy(heap2, l->heap, l->count * 8); +--- +> ast_SwitchCase** heap2 = malloc(l->capacity * 4); +> memcpy(heap2, l->heap, l->count * 4); +19323c19430 +< memset(l, 0, 48); +--- +> memset(l, 0, 28); +19332,19333c19439,19440 +< ast_Expr** data2 = malloc(l->capacity * 8); +< memcpy(data2, l->data, l->count * 8); +--- +> ast_Expr** data2 = malloc(l->capacity * 4); +> memcpy(data2, l->data, l->count * 4); +19383c19490 +< const char* s = token_Kind_str(k); +--- +> const char* s = token_Kind__name[k]; +19412c19519 +< memset(l, 0, 48); +--- +> memset(l, 0, 28); +19426,19427c19533,19534 +< ast_Stmt** data2 = malloc(l->capacity * 8); +< memcpy(data2, l->data, l->count * 8); +--- +> ast_Stmt** data2 = malloc(l->capacity * 4); +> memcpy(data2, l->data, l->count * 4); +19498c19605 +< diagnostics_Diags_errorRange(diags, ast_Expr_getLoc(e), ast_Expr_getRange(e), "constant value %s out-of-bounds for bitfield, range [%ld, %lu]", value_type_Value_str(&value), limit.min_val, limit.max_val); +--- +> diagnostics_Diags_errorRange(diags, ast_Expr_getLoc(e), ast_Expr_getRange(e), "constant value %s out-of-bounds for bitfield, range [%lld, %llu]", value_type_Value_str(&value), limit.min_val, limit.max_val); +19518c19625 +< diagnostics_Diags_errorRange(diags, loc, range, "constant value %s out-of-bounds for type '%s', range [%ld, %lu]", value_type_Value_str(value), ast_QualType_diagNameBare(qt), limit.min_val, limit.max_val); +--- +> diagnostics_Diags_errorRange(diags, loc, range, "constant value %s out-of-bounds for type '%s', range [%lld, %llu]", value_type_Value_str(value), ast_QualType_diagNameBare(qt), limit.min_val, limit.max_val); +19560c19667 +< incr_array_list_Info* entries2 = malloc(v->capacity * 56); +--- +> incr_array_list_Info* entries2 = malloc(v->capacity * 36); +19562c19669 +< memcpy(entries2, v->entries, v->count * 56); +--- +> memcpy(entries2, v->entries, v->count * 36); +19601a19709,19713 +> bool can_break; +> bool can_continue; +> bool has_goto; +> bool has_break; +> bool has_continue; +19635c19747 +< void* data2 = malloc(v->capacity * 24); +--- +> void* data2 = malloc(v->capacity * 20); +19637c19749 +< memcpy(data2, v->data, v->count * 24); +--- +> memcpy(data2, v->data, v->count * 20); +19681d19792 +< const module_list_List* allmodules; +19682a19794,19795 +> string_pool_Pool* astPool; +> const module_list_List* allmodules; +19708c19821 +< static scope_Scope* scope_create(module_list_List* allmodules, diagnostics_Diags* diags, const ast_ImportDeclList* imports, ast_Module* mod, const ast_SymbolTable* symbols, bool warn_on_unused); +--- +> static scope_Scope* scope_create(module_list_List* allmodules, diagnostics_Diags* diags, string_pool_Pool* astPool, const ast_ImportDeclList* imports, ast_Module* mod, const ast_SymbolTable* symbols, bool warn_on_unused); +19710a19824,19826 +> static const char* scope_Scope_idx2name(const scope_Scope* s, u32 name_idx); +> static const char* scope_Scope_getName(const scope_Scope* s, const ast_Decl* d); +> static const char* scope_Scope_getFullName(const scope_Scope* s, const ast_Decl* d); +19735c19851 +< static scope_Scope* scope_create(module_list_List* allmodules, diagnostics_Diags* diags, const ast_ImportDeclList* imports, ast_Module* mod, const ast_SymbolTable* symbols, bool warn_on_unused) +--- +> static scope_Scope* scope_create(module_list_List* allmodules, diagnostics_Diags* diags, string_pool_Pool* astPool, const ast_ImportDeclList* imports, ast_Module* mod, const ast_SymbolTable* symbols, bool warn_on_unused) +19737,19738c19853 +< scope_Scope* s = calloc(1, 376); +< s->allmodules = allmodules; +--- +> scope_Scope* s = calloc(1, 332); +19739a19855,19856 +> s->astPool = astPool; +> s->allmodules = allmodules; +19766a19884,19898 +> static const char* scope_Scope_idx2name(const scope_Scope* s, u32 name_idx) +> { +> return string_pool_Pool_idx2str(s->astPool, name_idx); +> } +> +> static const char* scope_Scope_getName(const scope_Scope* s, const ast_Decl* d) +> { +> return string_pool_Pool_idx2str(s->astPool, ast_Decl_getNameIdx(d)); +> } +> +> static const char* scope_Scope_getFullName(const scope_Scope* s, const ast_Decl* d) +> { +> return ast_Decl_getFullName(d); +> } +> +19775c19907 +< diagnostics_Diags_error(s->diags, ast_ImportDecl_getLoc(id), "duplicate import name '%s'", ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(s->diags, ast_ImportDecl_getLoc(id), "duplicate import name '%s'", scope_Scope_idx2name(s, name_idx)); +19783c19915 +< diagnostics_Diags_error(s->diags, ast_ImportDecl_getLoc(id), "import redefinition of '%s'", ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(s->diags, ast_ImportDecl_getLoc(id), "import redefinition of '%s'", scope_Scope_idx2name(s, name_idx)); +19820c19952 +< if (ast_VarDecl_isLocal(vd)) diagnostics_Diags_warn(s->diags, ast_Decl_getLoc(d), "unused variable '%s'", ast_Decl_getName(d)); +--- +> if (ast_VarDecl_isLocal(vd)) diagnostics_Diags_warn(s->diags, ast_Decl_getLoc(d), "unused variable '%s'", scope_Scope_getName(s, d)); +19846c19978 +< ast_Decl** decls = malloc(capacity * 8); +--- +> ast_Decl** decls = malloc(capacity * 4); +19850c19982 +< memcpy(decls, s->stack_decls, s->stack_count * 8); +--- +> memcpy(decls, s->stack_decls, s->stack_count * 4); +19861,19862c19993,19994 +< ast_Decl** decls = malloc(capacity * 8); +< ast_ImportDecl** imports = malloc(capacity * 8); +--- +> ast_Decl** decls = malloc(capacity * 4); +> ast_ImportDecl** imports = malloc(capacity * 4); +19866,19867c19998,19999 +< memcpy(decls, s->cache_decls, s->cache_count * 8); +< memcpy(imports, s->cache_imports, s->cache_count * 8); +--- +> memcpy(decls, s->cache_decls, s->cache_count * 4); +> memcpy(imports, s->cache_imports, s->cache_count * 4); +19924c20056 +< diagnostics_Diags_error(s->diags, ast_Decl_getLoc(d), "redefinition of '%s'", ast_Decl_getName(decl)); +--- +> diagnostics_Diags_error(s->diags, ast_Decl_getLoc(d), "redefinition of '%s'", scope_Scope_idx2name(s, name_idx)); +19931c20063 +< diagnostics_Diags_error(s->diags, ast_Decl_getLoc(d), "redefinition of '%s'", ast_Decl_getName(decl)); +--- +> diagnostics_Diags_error(s->diags, ast_Decl_getLoc(d), "redefinition of '%s'", scope_Scope_idx2name(s, name_idx)); +19948c20080 +< const char* name2 = ast_idx2name(s->stack_symbols[i]); +--- +> const char* name2 = scope_Scope_idx2name(s, s->stack_symbols[i]); +19963c20095 +< if (d) return ast_Decl_getFullName(d); +--- +> if (d) return scope_Scope_getFullName(s, d); +19972c20104 +< const char* name2 = ast_idx2name(st->symbols[j]); +--- +> const char* name2 = scope_Scope_idx2name(s, st->symbols[j]); +19998a20131 +> const char* name = scope_Scope_idx2name(s, name_idx); +20001c20134,20145 +< diagnostics_Diags_error(s->diags, loc, "module '%s' is imported with alias '%s'", ast_Decl_getName(ast_ImportDecl_asDecl(id)), ast_ImportDecl_getAliasName(id)); +--- +> const char* alias_name = scope_Scope_idx2name(s, ast_ImportDecl_getAliasNameIdx(id)); +> diagnostics_Diags_error(s->diags, loc, "module '%s' is imported with alias '%s'", name, alias_name); +> return NULL; +> } +> ast_Module* m = module_list_List_find(s->allmodules, name_idx); +> if (m) { +> diagnostics_Diags_error(s->diags, loc, "use of unimported module '%s'", name); +> return NULL; +> } +> const char* hint = scope_Scope_findBestMatch(s, name_idx, name, strlen(name)); +> if (hint) { +> diagnostics_Diags_error(s->diags, loc, "use of undeclared identifier '%s'; did you mean '%s'?", name, hint); +20003,20009c20147 +< const char* name = ast_idx2name(name_idx); +< const char* hint = scope_Scope_findBestMatch(s, name_idx, name, strlen(name)); +< if (hint) { +< diagnostics_Diags_error(s->diags, loc, "use of undeclared identifier '%s'; did you mean '%s'?", name, hint); +< } else { +< diagnostics_Diags_error(s->diags, loc, "use of undeclared identifier '%s'", name); +< } +--- +> diagnostics_Diags_error(s->diags, loc, "use of undeclared identifier '%s'", name); +20032c20170 +< diagnostics_Diags_error(s->diags, loc, "redefinition of '%s'", ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(s->diags, loc, "redefinition of '%s'", scope_Scope_idx2name(s, name_idx)); +20049c20187,20188 +< diagnostics_Diags_error(s->diags, loc, "module '%s' is imported with alias '%s'", ast_Decl_getName(ast_ImportDecl_asDecl(d)), ast_ImportDecl_getAliasName(d)); +--- +> const char* alias_name = scope_Scope_idx2name(s, ast_ImportDecl_getAliasNameIdx(d)); +> diagnostics_Diags_error(s->diags, loc, "module '%s' is imported with alias '%s'", scope_Scope_idx2name(s, name_idx), alias_name); +20054c20193 +< diagnostics_Diags_error(s->diags, loc, "module %s not imported", ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(s->diags, loc, "use of unimported module '%s'", scope_Scope_idx2name(s, name_idx)); +20056c20195 +< diagnostics_Diags_error(s->diags, loc, "unknown module: '%s'", ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(s->diags, loc, "unknown module: '%s'", scope_Scope_idx2name(s, name_idx)); +20066c20205 +< diagnostics_Diags_error(s->diags, loc, "module '%s' has no symbol '%s'", ast_Module_getName(mod), ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(s->diags, loc, "module '%s' has no symbol '%s'", ast_Module_getName(mod), scope_Scope_idx2name(s, name_idx)); +20071c20210 +< diagnostics_Diags_error(s->diags, loc, "symbol '%s' is not public", ast_Decl_getFullName(d)); +--- +> diagnostics_Diags_error(s->diags, loc, "symbol '%s' is not public", scope_Scope_getFullName(s, d)); +20088c20227 +< diagnostics_Diags_error(s->diags, loc, "unknown type '%s'", ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(s->diags, loc, "unknown type '%s'", scope_Scope_idx2name(s, name_idx)); +20124c20263 +< const char* name = ast_idx2name(name_idx); +--- +> const char* name = scope_Scope_idx2name(s, name_idx); +20127,20128c20266,20267 +< diagnostics_Diags_note(s->diags, ast_Decl_getLoc(decl), "did you mean '%s'?", ast_Decl_getFullName(decl)); +< diagnostics_Diags_note(s->diags, ast_Decl_getLoc(d), "did you mean '%s'?", ast_Decl_getFullName(d)); +--- +> diagnostics_Diags_note(s->diags, ast_Decl_getLoc(decl), "did you mean '%s'?", scope_Scope_getFullName(s, decl)); +> diagnostics_Diags_note(s->diags, ast_Decl_getLoc(d), "did you mean '%s'?", scope_Scope_getFullName(s, d)); +20132c20271 +< diagnostics_Diags_note(s->diags, ast_Decl_getLoc(d), "did you mean '%s'?", ast_Decl_getFullName(d)); +--- +> diagnostics_Diags_note(s->diags, ast_Decl_getLoc(d), "did you mean '%s'?", scope_Scope_getFullName(s, d)); +20165c20304,20305 +< diagnostics_Diags_error(s->diags, loc, "symbol '%s' is not public", ast_Decl_getFullName(d)); +--- +> diagnostics_Diags_error(s->diags, loc, "symbol '%s' is not public", scope_Scope_getFullName(s, d)); +> diagnostics_Diags_note(s->diags, ast_Decl_getLoc(d), "symbol definition is here"); +20185c20325,20326 +< diagnostics_Diags_error(s->diags, loc, "enum-associated value '%s' is not public", ast_Decl_getName(d)); +--- +> diagnostics_Diags_error(s->diags, loc, "enum-associated value '%s' is not public", scope_Scope_getName(s, d)); +> diagnostics_Diags_note(s->diags, ast_Decl_getLoc(d), "symbol definition is here"); +20189c20330,20331 +< diagnostics_Diags_error(s->diags, loc, "symbol '%s' is not public", ast_Decl_getFullName(d)); +--- +> diagnostics_Diags_error(s->diags, loc, "symbol '%s' is not public", scope_Scope_getFullName(s, d)); +> diagnostics_Diags_note(s->diags, ast_Decl_getLoc(d), "symbol definition is here"); +20322d20463 +< u32 pointerSize = ast_getWordSize(); +20328,20329c20469,20470 +< result.size = ast_BuiltinType_getAlignment(bi); +< result.align = result.size; +--- +> result.align = ast_BuiltinType_getAlignment(bi); +> result.size = result.align; +20334,20335c20475,20477 +< result.size = pointerSize; +< result.align = result.size; +--- +> case ast_TypeKind_Function: +> result.align = ast_Type_getAlignment(t); +> result.size = result.align; +20356,20359d20497 +< case ast_TypeKind_Function: +< result.size = pointerSize; +< result.align = pointerSize; +< break; +20412c20550 +< struct_func_list_Info* data2 = malloc(v->capacity * 24); +--- +> struct_func_list_Info* data2 = malloc(v->capacity * 16); +20414c20552 +< memcpy(data2, v->data, v->count * 24); +--- +> memcpy(data2, v->data, v->count * 16); +20453a20592 +> string_pool_Pool* astPool; +20457c20596,20599 +< static void unused_checker_check(diagnostics_Diags* diags, const warning_flags_Flags* warnings, ast_Module* mod); +--- +> static void unused_checker_check(diagnostics_Diags* diags, string_pool_Pool* astPool, const warning_flags_Flags* warnings, ast_Module* mod); +> static const char* unused_checker_Checker_idx2name(const unused_checker_Checker* c, u32 name_idx); +> static const char* unused_checker_Checker_getName(const unused_checker_Checker* c, const ast_Decl* d); +> static const char* unused_checker_Checker_getFullName(const unused_checker_Checker* c, const ast_Decl* d); +20464c20606 +< static void unused_checker_check(diagnostics_Diags* diags, const warning_flags_Flags* warnings, ast_Module* mod) +--- +> static void unused_checker_check(diagnostics_Diags* diags, string_pool_Pool* astPool, const warning_flags_Flags* warnings, ast_Module* mod) +20467a20610 +> .astPool = astPool, +20476a20620,20634 +> static const char* unused_checker_Checker_idx2name(const unused_checker_Checker* c, u32 name_idx) +> { +> return string_pool_Pool_idx2str(c->astPool, name_idx); +> } +> +> static const char* unused_checker_Checker_getName(const unused_checker_Checker* c, const ast_Decl* d) +> { +> return string_pool_Pool_idx2str(c->astPool, ast_Decl_getNameIdx(d)); +> } +> +> static const char* unused_checker_Checker_getFullName(const unused_checker_Checker* c, const ast_Decl* d) +> { +> return ast_Decl_getFullName(d); +> } +> +20481c20639 +< diagnostics_Diags_warn(c->diags, ast_AST_getLoc(a), "unused module '%s'", ast_AST_getName(a)); +--- +> diagnostics_Diags_warn(c->diags, ast_AST_getLoc(a), "unused module '%s'", unused_checker_Checker_idx2name(c, ast_AST_getNameIdx(a))); +20490c20648 +< diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(d), "%s '%s' is not used public", ast_Decl_getKindName(d), ast_Decl_getFullName(d)); +--- +> diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(d), "%s '%s' is not used public", ast_Decl_getKindName(d), unused_checker_Checker_getFullName(c, d)); +20531c20689 +< diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(d), "unused %s '%s'", ast_Decl_getKindName(d), ast_Decl_getFullName(d)); +--- +> diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(d), "unused %s '%s'", ast_Decl_getKindName(d), unused_checker_Checker_getFullName(c, d)); +20544c20702 +< diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(dd), "unused %s '%s'", ast_Decl_getKindName(dd), ast_Decl_getName(dd)); +--- +> diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(dd), "unused %s '%s'", ast_Decl_getKindName(dd), unused_checker_Checker_getName(c, dd)); +20560,20561c20718 +< const char* enum_name = ast_Decl_getFullName(ed); +< diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(d), "enum-associated value '%s' is not used public", ast_VarDecl_getEnumAssocValueName(vd, enum_name)); +--- +> diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(d), "enum-associated value '%s.%s' is not used public", unused_checker_Checker_getFullName(c, ed), unused_checker_Checker_getName(c, d)); +20566,20567c20723 +< const char* enum_name = ast_Decl_getFullName(ed); +< diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(d), "unused enum-associated value '%s'", ast_VarDecl_getEnumAssocValueName(vd, enum_name)); +--- +> diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(d), "unused enum-associated value '%s.%s'", unused_checker_Checker_getFullName(c, ed), unused_checker_Checker_getName(c, d)); +20583,20584c20739,20740 +< if (!ast_Decl_isUsed(member) && !c->warnings->no_unused_variable) { +< diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(member), "unused %s member '%s'", ast_StructTypeDecl_isStruct(std) ? "struct" : "union", ast_Decl_getName(member)); +--- +> if (!ast_Decl_isUsed(member) && !ast_Decl_hasAttrUnused(member) && !c->warnings->no_unused_variable) { +> diagnostics_Diags_warn(c->diags, ast_Decl_getLoc(member), "unused %s member '%s'", ast_StructTypeDecl_isStruct(std) ? "struct" : "union", unused_checker_Checker_getName(c, member)); +20702c20858 +< c2recipe_Recipe* r = calloc(1, 48); +--- +> c2recipe_Recipe* r = calloc(1, 32); +20706c20862 +< r->targets = calloc(r->max_targets, 8); +--- +> r->targets = calloc(r->max_targets, 4); +20730,20731c20886,20887 +< build_target_Target** targets2 = malloc(r->max_targets * 8); +< memcpy(targets2, r->targets, r->num_targets * 8); +--- +> build_target_Target** targets2 = malloc(r->max_targets * 4); +> memcpy(targets2, r->targets, r->num_targets * 4); +20768c20924 +< c2recipe_Set* s = calloc(1, 32); +--- +> c2recipe_Set* s = calloc(1, 24); +21529c21685 +< ast_visitor_Visitor* v = calloc(1, 24); +--- +> ast_visitor_Visitor* v = calloc(1, 12); +21638c21794,21795 +< ast_visitor_Visitor_handleStmt(v, ast_IfStmt_getCond(i)); +--- +> if (ast_IfStmt_hasDecl(i)) ast_visitor_Visitor_handleStmt(v, ast_IfStmt_getDecl(i)); +> if (ast_IfStmt_getCond(i)) ast_visitor_Visitor_handleExpr(v, ast_IfStmt_getCond(i)); +21640,21641c21797 +< ast_Stmt* e = ast_IfStmt_getElse(i); +< if (e) ast_visitor_Visitor_handleStmt(v, e); +--- +> if (ast_IfStmt_hasElse(i)) ast_visitor_Visitor_handleStmt(v, ast_IfStmt_getElse(i)); +21881d22036 +< break; +21884,21887d22038 +< case ast_BuiltinExprKind_EnumMin: +< break; +< case ast_BuiltinExprKind_EnumMax: +< break; +21913c22064 +< static void dep_finder_Finder_handleFunction(dep_finder_Finder* s, ast_FunctionDecl* d); +--- +> static void dep_finder_Finder_handleFunction(dep_finder_Finder* s, ast_FunctionDecl* d, bool full); +21916,21917c22067,22068 +< static void dep_finder_Finder_handleTypeRef(dep_finder_Finder* f, ast_TypeRef* r); +< static void dep_finder_Finder_handleVarDecl(dep_finder_Finder* s, ast_VarDecl* d); +--- +> static void dep_finder_Finder_handleTypeRef(dep_finder_Finder* f, ast_TypeRef* r, bool full); +> static void dep_finder_Finder_handleVarDecl(dep_finder_Finder* s, ast_VarDecl* d, bool full); +21936c22087 +< dep_finder_Finder_handleFunction(s, (ast_FunctionDecl*)d); +--- +> dep_finder_Finder_handleFunction(s, (ast_FunctionDecl*)d, true); +21946,21947c22097,22101 +< case ast_DeclKind_EnumConstant: +< ast_Decl_dump(d); +--- +> case ast_DeclKind_EnumConstant: { +> ast_QualType qt = ast_Decl_getType(d); +> ast_EnumType* et = ast_QualType_getEnumTypeOrNil(qt); +> ast_EnumTypeDecl* etd = ast_EnumType_getDecl(et); +> dep_finder_Finder_handleEnumType(s, etd); +21948a22103 +> } +21951c22106 +< dep_finder_Finder_handleFunction(s, ast_FunctionTypeDecl_getDecl(ftd)); +--- +> dep_finder_Finder_handleFunction(s, ast_FunctionTypeDecl_getDecl(ftd), false); +21956c22111 +< dep_finder_Finder_handleTypeRef(s, ast_AliasTypeDecl_getTypeRef(at)); +--- +> dep_finder_Finder_handleTypeRef(s, ast_AliasTypeDecl_getTypeRef(at), false); +21960c22115 +< dep_finder_Finder_handleVarDecl(s, (ast_VarDecl*)d); +--- +> dep_finder_Finder_handleVarDecl(s, (ast_VarDecl*)d, true); +21965c22120 +< static void dep_finder_Finder_handleFunction(dep_finder_Finder* s, ast_FunctionDecl* d) +--- +> static void dep_finder_Finder_handleFunction(dep_finder_Finder* s, ast_FunctionDecl* d, bool full) +21968c22123 +< dep_finder_Finder_handleTypeRef(s, ast_FunctionDecl_getReturnTypeRef(d)); +--- +> dep_finder_Finder_handleTypeRef(s, ast_FunctionDecl_getReturnTypeRef(d), full); +21971c22126 +< for (u32 i = 0; i < num_params; i++) dep_finder_Finder_handleVarDecl(s, args[i]); +--- +> for (u32 i = 0; i < num_params; i++) dep_finder_Finder_handleVarDecl(s, args[i], full); +21984c22139 +< dep_finder_Finder_handleVarDecl(s, (ast_VarDecl*)m); +--- +> dep_finder_Finder_handleVarDecl(s, (ast_VarDecl*)m, true); +22001c22156 +< static void dep_finder_Finder_handleTypeRef(dep_finder_Finder* f, ast_TypeRef* r) +--- +> static void dep_finder_Finder_handleTypeRef(dep_finder_Finder* f, ast_TypeRef* r, bool full) +22005c22160 +< if (ast_TypeRef_isPointer(r) && ast_Decl_isStructType(refDecl)) { +--- +> if ((ast_TypeRef_isPointer(r) || !full) && ast_Decl_isStructType(refDecl)) { +22017c22172 +< static void dep_finder_Finder_handleVarDecl(dep_finder_Finder* s, ast_VarDecl* d) +--- +> static void dep_finder_Finder_handleVarDecl(dep_finder_Finder* s, ast_VarDecl* d, bool full) +22019c22174 +< dep_finder_Finder_handleTypeRef(s, ast_VarDecl_getTypeRef(d)); +--- +> dep_finder_Finder_handleTypeRef(s, ast_VarDecl_getTypeRef(d), full); +22042c22197 +< dep_finder_Finder_handleTypeRef(s, ast_TypeExpr_getTypeRef(t)); +--- +> dep_finder_Finder_handleTypeRef(s, ast_TypeExpr_getTypeRef(t), true); +22104c22259 +< dep_finder_Finder_handleTypeRef(s, ast_ExplicitCastExpr_getTypeRef(c)); +--- +> dep_finder_Finder_handleTypeRef(s, ast_ExplicitCastExpr_getTypeRef(c), true); +22166a22322,22325 +> // --- module label_map --- +> +> +> +22186a22346 +> string_pool_Pool* astPool; +22193c22353 +< static attr_handler_Handler* attr_handler_create(diagnostics_Diags* diags, const warning_flags_Flags* warnings); +--- +> static attr_handler_Handler* attr_handler_create(diagnostics_Diags* diags, string_pool_Pool* astPool, const warning_flags_Flags* warnings); +22198c22358 +< static attr_handler_Handler* attr_handler_create(diagnostics_Diags* diags, const warning_flags_Flags* warnings) +--- +> static attr_handler_Handler* attr_handler_create(diagnostics_Diags* diags, string_pool_Pool* astPool, const warning_flags_Flags* warnings) +22200c22360 +< attr_handler_Handler* h = calloc(1, 32); +--- +> attr_handler_Handler* h = calloc(1, 24); +22201a22362 +> h->astPool = astPool; +22216c22377 +< attr_handler_Entry* entries2 = malloc(h->capacity * 24); +--- +> attr_handler_Entry* entries2 = malloc(h->capacity * 12); +22218c22379 +< memcpy(entries2, h->entries, h->count * 24); +--- +> memcpy(entries2, h->entries, h->count * 12); +22238c22399 +< diagnostics_Diags_warn(h->diags, a->loc, "unknown attribute '%s'", ast_idx2name(a->name)); +--- +> diagnostics_Diags_warn(h->diags, a->loc, "unknown attribute '%s'", string_pool_Pool_idx2str(h->astPool, a->name)); +22285c22446 +< static const char* component_kind_names[9] = { +--- +> static const char* const component_Kind__name[9] = { +22337c22498 +< component_Component* c = calloc(1, 104); +--- +> component_Component* c = calloc(1, 72); +22494c22655 +< string_buffer_Buf_print(out, "--- %s [%s]", component_Component_getName(c), component_kind_names[c->kind]); +--- +> string_buffer_Buf_print(out, "--- %s [%s]", component_Component_getName(c), component_Kind__name[c->kind]); +22513c22674 +< string_buffer_Buf_print(out, "--- %s [%s] ---\n", component_Component_getName(c), component_kind_names[c->kind]); +--- +> string_buffer_Buf_print(out, "--- %s [%s] ---\n", component_Component_getName(c), component_Kind__name[c->kind]); +22559c22720 +< component_Component** comps2 = malloc(l->capacity * 8); +--- +> component_Component** comps2 = malloc(l->capacity * 4); +22561c22722 +< memcpy(comps2, l->components, l->count * 8); +--- +> memcpy(comps2, l->components, l->count * 4); +22634a22796,22797 +> ast_BuiltinKind native_kind; +> ast_BuiltinKind native_long; +22641a22805 +> static const char* ast_builder_Builder_idx2name(const ast_builder_Builder* b, u32 name_idx); +22644a22809,22810 +> static ast_BuiltinKind ast_builder_Builder_getNativeKind(ast_builder_Builder* b); +> static ast_BuiltinKind ast_builder_Builder_getNativeLong(ast_builder_Builder* b); +22687c22853 +< static ast_Stmt* ast_builder_Builder_actOnIfStmt(ast_builder_Builder* b, src_loc_SrcLoc loc, ast_Stmt* cond, ast_Stmt* then, ast_Stmt* else_stmt); +--- +> static ast_Stmt* ast_builder_Builder_actOnIfStmt(ast_builder_Builder* b, src_loc_SrcLoc loc, ast_Stmt* decl, ast_Expr* cond, ast_Stmt* then, ast_Stmt* else_stmt); +22693,22694c22859,22860 +< static ast_Stmt* ast_builder_Builder_actOnBreakStmt(ast_builder_Builder* b, src_loc_SrcLoc loc); +< static ast_Stmt* ast_builder_Builder_actOnContinueStmt(ast_builder_Builder* b, src_loc_SrcLoc loc); +--- +> static ast_Stmt* ast_builder_Builder_actOnBreakStmt(ast_builder_Builder* b, src_loc_SrcLoc loc, u32 name_idx); +> static ast_Stmt* ast_builder_Builder_actOnContinueStmt(ast_builder_Builder* b, src_loc_SrcLoc loc, u32 name_idx); +22731c22897 +< ast_builder_Builder* b = calloc(1, 344); +--- +> ast_builder_Builder* b = calloc(1, 244); +22737a22904,22905 +> b->native_kind = ast_context_Context_getPointerSize(context) == 8 ? ast_BuiltinKind_UInt64 : ast_BuiltinKind_UInt32; +> b->native_long = ast_context_Context_getLongSize(context) == 8 ? ast_BuiltinKind_Int64 : ast_BuiltinKind_Int32; +22746a22915,22919 +> static const char* ast_builder_Builder_idx2name(const ast_builder_Builder* b, u32 name_idx) +> { +> return string_pool_Pool_idx2str(b->astPool, name_idx); +> } +> +22768a22942,22951 +> static ast_BuiltinKind ast_builder_Builder_getNativeKind(ast_builder_Builder* b) +> { +> return b->native_kind; +> } +> +> static ast_BuiltinKind ast_builder_Builder_getNativeLong(ast_builder_Builder* b) +> { +> return b->native_long; +> } +> +22796c22979 +< diagnostics_Diags_error(b->diags, mod_loc, "cannot import own module '%s'", ast_idx2name(mod_name)); +--- +> diagnostics_Diags_error(b->diags, mod_loc, "cannot import own module '%s'", ast_builder_Builder_idx2name(b, mod_name)); +22803c22986 +< diagnostics_Diags_error(b->diags, mod_loc, "duplicate import of module '%s'", ast_idx2name(mod_name)); +--- +> diagnostics_Diags_error(b->diags, mod_loc, "duplicate import of module '%s'", ast_builder_Builder_idx2name(b, mod_name)); +22834c23017 +< ast_FunctionTypeDecl* d = ast_FunctionTypeDecl_create(b->context, fd); +--- +> ast_FunctionTypeDecl* d = ast_FunctionTypeDecl_create(b->context, fd, b->ast_idx); +22902c23085 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> string_buffer_Buf_add(out, ast_builder_Builder_idx2name(b, ast_Decl_getNameIdx(d))); +22904c23087 +< string_buffer_Buf_add(out, ast_idx2name(ast_Decl_getNameIdx(esv))); +--- +> string_buffer_Buf_add(out, ast_builder_Builder_idx2name(b, ast_Decl_getNameIdx(esv))); +22907,22908c23090,23092 +< ast_TypeRefHolder ref; ast_TypeRefHolder_init(&ref); +< ast_TypeRefHolder_setBuiltin(&ref, ast_BuiltinKind_Char, 0); +--- +> ast_VarDecl* vd_esv = (ast_VarDecl*)esv; +> ast_TypeRefHolder ref; ast_TypeRefHolder_copy(&ref, ast_VarDecl_getTypeRef(vd_esv)); +> ast_TypeRefHolder_addPointer(&ref); +23179c23363 +< diagnostics_Diags_error(b->diags, a->loc, "attribute '%s' cannot be applied to function parameters", ast_idx2name(a->name)); +--- +> diagnostics_Diags_error(b->diags, a->loc, "attribute '%s' cannot be applied to function parameters", ast_builder_Builder_idx2name(b, a->name)); +23387c23571 +< static ast_Stmt* ast_builder_Builder_actOnIfStmt(ast_builder_Builder* b, src_loc_SrcLoc loc, ast_Stmt* cond, ast_Stmt* then, ast_Stmt* else_stmt) +--- +> static ast_Stmt* ast_builder_Builder_actOnIfStmt(ast_builder_Builder* b, src_loc_SrcLoc loc, ast_Stmt* decl, ast_Expr* cond, ast_Stmt* then, ast_Stmt* else_stmt) +23389c23573 +< return (ast_Stmt*)ast_IfStmt_create(b->context, loc, cond, then, else_stmt); +--- +> return (ast_Stmt*)ast_IfStmt_create(b->context, loc, decl, cond, then, else_stmt); +23417c23601 +< static ast_Stmt* ast_builder_Builder_actOnBreakStmt(ast_builder_Builder* b, src_loc_SrcLoc loc) +--- +> static ast_Stmt* ast_builder_Builder_actOnBreakStmt(ast_builder_Builder* b, src_loc_SrcLoc loc, u32 name_idx) +23419c23603 +< return (ast_Stmt*)ast_BreakStmt_create(b->context, loc); +--- +> return (ast_Stmt*)ast_BreakStmt_create(b->context, loc, name_idx); +23422c23606 +< static ast_Stmt* ast_builder_Builder_actOnContinueStmt(ast_builder_Builder* b, src_loc_SrcLoc loc) +--- +> static ast_Stmt* ast_builder_Builder_actOnContinueStmt(ast_builder_Builder* b, src_loc_SrcLoc loc, u32 name_idx) +23424c23608 +< return (ast_Stmt*)ast_ContinueStmt_create(b->context, loc); +--- +> return (ast_Stmt*)ast_ContinueStmt_create(b->context, loc, name_idx); +23590c23774 +< diagnostics_Diags_error(b->diags, ast_Decl_getLoc(d), "redefinition of '%s'", ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(b->diags, ast_Decl_getLoc(d), "redefinition of '%s'", ast_builder_Builder_idx2name(b, name_idx)); +23640,23641c23824,23825 +< component_Component** copy = malloc(count * 8); +< memcpy(copy, orig, count * 8); +--- +> component_Component** copy = malloc(count * 4); +> memcpy(copy, orig, count * 4); +23804c23988 +< const string_list_List* features; +--- +> const string_map_Map* features; +23983c24167 +< static void c2_tokenizer_Tokenizer_init(c2_tokenizer_Tokenizer* t, string_pool_Pool* pool, string_buffer_Buf* buf, const char* input, src_loc_SrcLoc loc_start, const keywords_Info* kwinfo, const string_list_List* features, c2_tokenizer_ErrorFn on_error, void* on_error_arg, bool raw_mode); +--- +> static void c2_tokenizer_Tokenizer_init(c2_tokenizer_Tokenizer* t, string_pool_Pool* pool, string_buffer_Buf* buf, const char* input, src_loc_SrcLoc loc_start, const keywords_Info* kwinfo, const string_map_Map* features, c2_tokenizer_ErrorFn on_error, void* on_error_arg, bool raw_mode); +24022c24206 +< static void c2_tokenizer_Tokenizer_init(c2_tokenizer_Tokenizer* t, string_pool_Pool* pool, string_buffer_Buf* buf, const char* input, src_loc_SrcLoc loc_start, const keywords_Info* kwinfo, const string_list_List* features, c2_tokenizer_ErrorFn on_error, void* on_error_arg, bool raw_mode) +--- +> static void c2_tokenizer_Tokenizer_init(c2_tokenizer_Tokenizer* t, string_pool_Pool* pool, string_buffer_Buf* buf, const char* input, src_loc_SrcLoc loc_start, const keywords_Info* kwinfo, const string_map_Map* features, c2_tokenizer_ErrorFn on_error, void* on_error_arg, bool raw_mode) +24024c24208 +< memset(t, 0, 408); +--- +> memset(t, 0, 360); +24375c24559 +< c2_tokenizer_Tokenizer_error(t, result, "un-terminated %s", token_Kind_str(top->kind)); +--- +> c2_tokenizer_Tokenizer_error(t, result, "un-terminated %s", token_Kind__name[top->kind]); +25097c25281 +< const char* word = token_Kind_str(kind) + 1; +--- +> const char* word = token_Kind__name[kind] + 1; +25217c25401 +< value_type_Value_setUnsigned(&val, string_list_List_contains(t->features, id)); +--- +> value_type_Value_setUnsigned(&val, string_map_Map_contains(t->features, id, NULL)); +25219c25403,25408 +< value_type_Value_setUnsigned(&val, string_list_List_contains(t->features, id)); +--- +> i64 value = 0; +> u32 idx = 0; +> if (string_map_Map_contains(t->features, id, &idx)) { +> value = strtol(string_map_Map_getValue(t->features, idx), NULL, 0); +> } +> value_type_Value_setSigned(&val, value); +25336c25525 +< c2_tokenizer_Tokenizer_error(t, result, "invalid token in preprocessor expression '%s'", token_Kind_str(result->kind)); +--- +> c2_tokenizer_Tokenizer_error(t, result, "invalid token in preprocessor expression '%s'", token_Kind__name[result->kind]); +25413c25602 +< c2_tokenizer_Tokenizer_error(t, result, "invalid token in preprocessor expression '%s'", token_Kind_str(sp->op)); +--- +> c2_tokenizer_Tokenizer_error(t, result, "invalid token in preprocessor expression '%s'", token_Kind__name[sp->op]); +25464c25653 +< c2_tokenizer_Tokenizer_error(t, result, "%s without #if", token_Kind_str(kind)); +--- +> c2_tokenizer_Tokenizer_error(t, result, "%s without #if", token_Kind__name[kind]); +25468c25657 +< c2_tokenizer_Tokenizer_error(t, result, "%s in #else", token_Kind_str(kind)); +--- +> c2_tokenizer_Tokenizer_error(t, result, "%s in #else", token_Kind__name[kind]); +25481c25670,25675 +< if (!string_list_List_contains(t->features, string_pool_Pool_idx2str(t->pool, result->name_idx))) top->skipping = 1; +--- +> i64 value = 0; +> u32 idx = 0; +> if (string_map_Map_contains(t->features, string_pool_Pool_idx2str(t->pool, result->name_idx), &idx)) { +> value = strtol(string_map_Map_getValue(t->features, idx), NULL, 0); +> } +> if (!value) top->skipping = 1; +25484c25678 +< c2_tokenizer_Tokenizer_error(t, result, "missing identifier after %s, got %s", token_Kind_str(kind), token_Kind_str(result->kind)); +--- +> c2_tokenizer_Tokenizer_error(t, result, "missing identifier after %s, got %s", token_Kind__name[kind], token_Kind__name[result->kind]); +25525c25719 +< c2_tokenizer_Tokenizer_error(t, result, "un-terminated %s", token_Kind_str(top->kind)); +--- +> c2_tokenizer_Tokenizer_error(t, result, "un-terminated %s", token_Kind__name[top->kind]); +25675,25684d25868 +< typedef void* (*plugin_info_LoadFn)(const char* options, bool console_timing, bool console_debug); +< +< typedef void (*plugin_info_UnloadFn)(void* arg); +< +< typedef void (*plugin_info_InitFn)(void* arg, plugin_info_Info* info); +< +< typedef void (*plugin_info_PostParseFn)(void* arg); +< +< typedef void (*plugin_info_PostAnalysisFn)(void* arg); +< +25686,25690c25870,25874 +< plugin_info_LoadFn load; +< plugin_info_UnloadFn unload; +< plugin_info_InitFn init; +< plugin_info_PostParseFn post_parse; +< plugin_info_PostAnalysisFn post_analysis; +--- +> void* (*load)(const char* options, console_Config* config); +> void (*unload)(void* arg); +> void (*init)(void* arg, plugin_info_Info* info); +> void (*post_parse)(void* arg); +> void (*post_analysis)(void* arg); +25722,25767c25906,26092 +< { 0, 3, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 7 }, +< { 3, 0, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 3, 7 }, +< { 4, 4, 0, 1, 1, 4, 3, 3, 3, 1, 1, 1, 3, 7 }, +< { 4, 4, 4, 7, 1, 4, 4, 3, 3, 1, 1, 1, 3, 7 }, +< { 4, 4, 4, 4, 7, 4, 4, 4, 3, 1, 1, 7, 3, 7 }, +< { 1, 3, 1, 1, 1, 0, 1, 1, 1, 1, 1, 3, 1, 7 }, +< { 4, 4, 3, 1, 1, 4, 0, 1, 1, 1, 1, 3, 1, 7 }, +< { 4, 4, 4, 3, 1, 4, 4, 7, 1, 1, 1, 3, 1, 7 }, +< { 4, 4, 4, 4, 3, 4, 4, 4, 7, 1, 1, 3, 7, 7 }, +< { 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 1, 5, 5, 2 }, +< { 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, 5, 5, 2 }, +< { 4, 4, 4, 4, 7, 4, 4, 4, 3, 1, 1, 0, 3, 7 }, +< { 4, 4, 4, 4, 3, 4, 4, 4, 7, 1, 1, 3, 0, 7 }, +< { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 } +< }; +< static const u8 conversion_checker_ConditionalOperatorResult[14][14] = { +< { 0, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 }, +< { 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1 }, +< { 2, 2, 2, 3, 4, 2, 6, 7, 8, 9, 10, 11, 12, 2 }, +< { 3, 3, 3, 3, 4, 3, 3, 7, 8, 9, 10, 11, 12, 3 }, +< { 4, 4, 4, 4, 4, 4, 4, 4, 8, 9, 10, 11, 12, 4 }, +< { 5, 5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 5 }, +< { 6, 6, 6, 3, 4, 6, 6, 7, 8, 9, 10, 11, 12, 6 }, +< { 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 12, 7 }, +< { 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 8 }, +< { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 9, 9, 9 }, +< { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }, +< { 11, 11, 11, 11, 11, 11, 11, 11, 8, 9, 10, 11, 12, 11 }, +< { 12, 12, 12, 12, 12, 12, 12, 12, 8, 9, 10, 12, 12, 12 }, +< { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 } +< }; +< static const u8 conversion_checker_UsualArithmeticConversions[14][14] = { +< { 0, 0, 0, 0, 2, 0, 0, 1, 3, 4, 5, 6, 6, 0 }, +< { 0, 0, 0, 0, 2, 0, 0, 1, 3, 4, 5, 6, 6, 0 }, +< { 0, 0, 0, 0, 2, 0, 0, 1, 3, 4, 5, 6, 6, 0 }, +< { 0, 0, 0, 0, 2, 0, 0, 1, 3, 4, 5, 6, 6, 0 }, +< { 2, 2, 2, 3, 2, 2, 2, 2, 3, 4, 5, 6, 6, 2 }, +< { 0, 0, 0, 0, 2, 0, 0, 1, 3, 4, 5, 6, 6, 0 }, +< { 0, 0, 0, 0, 2, 0, 0, 1, 3, 4, 5, 6, 6, 0 }, +< { 1, 1, 1, 1, 3, 1, 1, 1, 3, 4, 5, 6, 6, 1 }, +< { 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 6, 6, 3 }, +< { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4 }, +< { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, +< { 6, 6, 6, 6, 6, 6, 6, 6, 3, 4, 5, 6, 6, 6 }, +< { 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 5, 6, 6, 6 }, +< { 0, 0, 0, 0, 2, 0, 0, 1, 3, 4, 5, 6, 6, 0 } +--- +> { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, +> { 7, 0, 3, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1 }, +> { 7, 3, 0, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 3 }, +> { 7, 4, 4, 0, 1, 1, 4, 3, 3, 3, 1, 1, 1, 3 }, +> { 7, 4, 4, 4, 7, 1, 4, 4, 3, 3, 1, 1, 1, 3 }, +> { 7, 4, 4, 4, 4, 7, 4, 4, 4, 3, 1, 1, 7, 3 }, +> { 7, 1, 3, 1, 1, 1, 0, 1, 1, 1, 1, 1, 3, 1 }, +> { 7, 4, 4, 3, 1, 1, 4, 0, 1, 1, 1, 1, 3, 1 }, +> { 7, 4, 4, 4, 3, 1, 4, 4, 7, 1, 1, 1, 3, 1 }, +> { 7, 4, 4, 4, 4, 3, 4, 4, 4, 7, 1, 1, 3, 7 }, +> { 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 1, 5, 5 }, +> { 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, 5, 5 }, +> { 7, 4, 4, 4, 4, 7, 4, 4, 4, 3, 1, 1, 0, 3 }, +> { 7, 4, 4, 4, 4, 3, 4, 4, 4, 7, 1, 1, 3, 0 } +> }; +> #define conversion_checker_X ast_BuiltinKind_Bool +> static const ast_BuiltinKind conversion_checker_ConditionalOperatorResult[14][14] = { +> { +> ast_BuiltinKind_Bool, ast_BuiltinKind_Char, ast_BuiltinKind_Int8, ast_BuiltinKind_Int16, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_UInt8, ast_BuiltinKind_UInt16, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Char, ast_BuiltinKind_Char, ast_BuiltinKind_Int16, ast_BuiltinKind_Int16, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_UInt8, ast_BuiltinKind_UInt16, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int8, ast_BuiltinKind_Int16, ast_BuiltinKind_Int8, ast_BuiltinKind_Int16, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_UInt8, ast_BuiltinKind_UInt16, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int16, ast_BuiltinKind_Int16, ast_BuiltinKind_Int16, ast_BuiltinKind_Int16, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int16, ast_BuiltinKind_UInt16, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, +> ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, +> ast_BuiltinKind_Int64, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_UInt8, ast_BuiltinKind_UInt8, ast_BuiltinKind_UInt8, ast_BuiltinKind_Int16, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_UInt8, ast_BuiltinKind_UInt16, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_UInt16, ast_BuiltinKind_UInt16, ast_BuiltinKind_UInt16, ast_BuiltinKind_UInt16, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_UInt16, ast_BuiltinKind_UInt16, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_Int64, ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, +> ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, +> ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, +> ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, +> ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, +> ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, +> ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X +> }, +> { +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X +> } +> }; +> static const ast_BuiltinKind conversion_checker_UsualArithmeticConversions[14][14] = { +> { +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, +> ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, ast_BuiltinKind_Int64, +> ast_BuiltinKind_Int64, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_Int32, ast_BuiltinKind_Int64, ast_BuiltinKind_Int32, ast_BuiltinKind_Int32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_Int64, ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt32, +> ast_BuiltinKind_UInt32, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, +> ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, +> ast_BuiltinKind_UInt64, ast_BuiltinKind_UInt64, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, +> ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, +> ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float32, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, +> ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, +> ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, ast_BuiltinKind_Float64, +> conversion_checker_X, conversion_checker_X +> }, +> { +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X +> }, +> { +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X, conversion_checker_X, conversion_checker_X, +> conversion_checker_X, conversion_checker_X +> } +25771c26096,26097 +< static bool conversion_checker_Checker_check(conversion_checker_Checker* c, ast_QualType lhs, ast_QualType rhs, ast_Expr** e_ptr, src_loc_SrcLoc loc); +--- +> static bool conversion_checker_Checker_shouldNotHappen(conversion_checker_Checker* c, const char* from, const ast_Type* lcanon, const ast_Type* rcanon, u8 res); +> static bool conversion_checker_Checker_checkAssign(conversion_checker_Checker* c, ast_QualType lhs, ast_QualType rhs, ast_Expr** e_ptr, src_loc_SrcLoc loc); +25790c26116 +< static ast_QualType conversion_checker_usual_arithmetic_conversion(const ast_BuiltinType* b1, const ast_BuiltinType* b2); +--- +> static ast_QualType conversion_checker_usual_arithmetic_conversion(const ast_BuiltinType* bi1, const ast_BuiltinType* bi2); +25808c26134 +< c->native_kind = ast_getNativeKind(); +--- +> c->native_kind = ast_builder_Builder_getNativeKind(builder); +25817c26143,26152 +< static bool conversion_checker_Checker_check(conversion_checker_Checker* c, ast_QualType lhs, ast_QualType rhs, ast_Expr** e_ptr, src_loc_SrcLoc loc) +--- +> static bool conversion_checker_Checker_shouldNotHappen(conversion_checker_Checker* c, const char* from, const ast_Type* lcanon, const ast_Type* rcanon, u8 res) +> { +> diagnostics_Diags_error(c->diags, c->loc, "%s: SHOULD NOT HAPPEN (%s -> %s, res=%d)\n", from, ast_TypeKind__name[ast_Type_getKind(rcanon)], ast_TypeKind__name[ast_Type_getKind(lcanon)], res); +> ast_QualType_dump_full(c->lhs); +> ast_QualType_dump_full(c->rhs); +> ;//assert(0); +> return false; +> } +> +> static bool conversion_checker_Checker_checkAssign(conversion_checker_Checker* c, ast_QualType lhs, ast_QualType rhs, ast_Expr** e_ptr, src_loc_SrcLoc loc) +25830,25832c26165 +< if (lcanon == rcanon) { +< return true; +< } +--- +> if (lcanon == rcanon) return true; +25845,25849c26178 +< diagnostics_Diags_error(c->diags, c->loc, "SHOULD NOT HAPPEN (%d - %d)\n", ast_Type_getKind(lcanon), ast_Type_getKind(rcanon)); +< ast_QualType_dump_full(c->lhs); +< ast_QualType_dump_full(c->rhs); +< ;//assert(0); +< return false; +--- +> break; +25850a26180,26183 +> case 8: +> case 13: +> case 14: +> case 15: +25863,25869c26196 +< diagnostics_Diags_note(c->diags, c->loc, "SHOULD NOT HAPPEN (Array -> Ptr)"); +< ast_QualType_dump_full(c->lhs); +< ast_QualType_dump_full(c->rhs); +< ;//assert(0); +< return false; +< case 8: +< return conversion_checker_Checker_conversionError(c, "invalid type conversion from"); +--- +> break; +25878,25881d26204 +< case 13: +< case 14: +< case 15: +< return conversion_checker_Checker_conversionError(c, "invalid type conversion from"); +25887,25888c26210 +< diagnostics_Diags_note(c->diags, c->loc, "TODO CONVERSION %d)", res); +< return false; +--- +> break; +25889a26212 +> return conversion_checker_Checker_shouldNotHappen(c, "conversion_checker.Checker.checkTypes", lcanon, rcanon, res); +25902,25904c26225 +< diagnostics_Diags_error(c->diags, c->loc, "BUILTIN SHOULD NOT HAPPEN (%d - %d)\n", ast_Type_getKind(lcanon), ast_Type_getKind(rcanon)); +< ;//assert(0); +< return false; +--- +> break; +25907c26228 +< break; +--- +> return true; +25916c26237 +< break; +--- +> return true; +25923c26244 +< break; +--- +> return true; +25926c26247 +< break; +--- +> return true; +25933c26254 +< break; +--- +> return true; +25935c26256 +< break; +--- +> return true; +25937,25938c26258 +< ;//assert(0); +< return false; +--- +> break; +25940c26260 +< return true; +--- +> return conversion_checker_Checker_shouldNotHappen(c, "conversion_checker.Checker.checkBuiltins", lcanon, rcanon, res); +26082c26402 +< return conversion_checker_Checker_check(c, c->lhs, impl, c->expr_ptr, c->loc); +--- +> return conversion_checker_Checker_checkAssign(c, c->lhs, impl, c->expr_ptr, c->loc); +26109a26430 +> if (ast_FunctionDecl_isVariadic(fdl) != ast_FunctionDecl_isVariadic(fdr)) return false; +26115,26122c26436,26441 +< ql = ast_Decl_getType(a1); +< qr = ast_Decl_getType(a2); +< if (ql.ptr != qr.ptr) { +< if (ast_QualType_isFunction(ql) && ast_QualType_isFunction(qr)) { +< ast_FunctionType* ft = ast_QualType_getFunctionType(ql); +< ast_FunctionDecl* fd1 = ast_FunctionType_getDecl(ft); +< ft = ast_QualType_getFunctionType(qr); +< ast_FunctionDecl* fd2 = ast_FunctionType_getDecl(ft); +--- +> ast_QualType qt1 = ast_Decl_getType(a1); +> ast_QualType qt2 = ast_Decl_getType(a2); +> if (qt1.ptr != qt2.ptr) { +> if (ast_QualType_isFunction(qt1) && ast_QualType_isFunction(qt2)) { +> ast_FunctionDecl* fd1 = ast_FunctionType_getDecl(ast_QualType_getFunctionType(qt1)); +> ast_FunctionDecl* fd2 = ast_FunctionType_getDecl(ast_QualType_getFunctionType(qt2)); +26128d26446 +< if (ast_FunctionDecl_isVariadic(fdl) != ast_FunctionDecl_isVariadic(fdr)) return false; +26146c26464 +< diagnostics_Diags_error(c->diags, c->loc, "pointers may only be cast to integer type '%s'", ast_BuiltinKind_str(c->native_kind)); +--- +> diagnostics_Diags_error(c->diags, c->loc, "pointers may only be cast to integer type '%s'", ast_BuiltinKind__name[c->native_kind]); +26167,26171c26485 +< diagnostics_Diags_error(c->diags, lhsLoc, "SHOULD NOT HAPPEN (%d - %d)\n", ast_Type_getKind(lcanon), ast_Type_getKind(rcanon)); +< ast_QualType_dump_full(c->lhs); +< ast_QualType_dump_full(c->rhs); +< ;//assert(0); +< return false; +--- +> break; +26175,26179d26488 +< return true; +< case 3: +< return conversion_checker_Checker_checkBuiltin2PointerCast(c, lcanon, rcanon); +< case 4: +< return conversion_checker_Checker_checkPointer2BuiltinCast(c, lcanon, rcanon); +26181d26489 +< return true; +26183,26195d26490 +< return true; +< case 7: +< diagnostics_Diags_note(c->diags, c->loc, "SHOULD NOT HAPPEN (Array -> Ptr)"); +< ;//assert(0); +< return false; +< case 8: +< diagnostics_Diags_error(c->diags, lhsLoc, "SHOULD NOT HAPPEN (%d - %d)\n", ast_Type_getKind(lcanon), ast_Type_getKind(rcanon)); +< ;//assert(0); +< return false; +< case 9: +< diagnostics_Diags_error(c->diags, lhsLoc, "SHOULD NOT HAPPEN (%d - %d)\n", ast_Type_getKind(lcanon), ast_Type_getKind(rcanon)); +< ;//assert(0); +< return false; +26197d26491 +< return true; +26199d26492 +< return true; +26201d26493 +< return true; +26203d26494 +< return true; +26205a26497,26504 +> case 3: +> return conversion_checker_Checker_checkBuiltin2PointerCast(c, lcanon, rcanon); +> case 4: +> return conversion_checker_Checker_checkPointer2BuiltinCast(c, lcanon, rcanon); +> case 7: +> case 8: +> case 9: +> break; +26211,26212c26510 +< diagnostics_Diags_note(c->diags, c->loc, "TODO CONVERSION %d)", res); +< return false; +--- +> break; +26213a26512 +> return conversion_checker_Checker_shouldNotHappen(c, "conversion_checker.Checker.checkCast", lcanon, rcanon, res); +26222c26521 +< diagnostics_Diags_error(c->diags, c->loc, "only integers of type '%s' may be cast to a pointer", ast_BuiltinKind_str(c->native_kind)); +--- +> diagnostics_Diags_error(c->diags, c->loc, "only integers of type '%s' may be cast to a pointer", ast_BuiltinKind__name[c->native_kind]); +26232c26531 +< diagnostics_Diags_error(c->diags, c->loc, "pointers may only be cast to integer type '%s'", ast_BuiltinKind_str(c->native_kind)); +--- +> diagnostics_Diags_error(c->diags, c->loc, "pointers may only be cast to integer type '%s'", ast_BuiltinKind__name[c->native_kind]); +26238,26239c26537 +< ast_BuiltinKind kind = (ast_BuiltinKind)conversion_checker_ConditionalOperatorResult[ast_BuiltinType_getBaseKind(bi2)][ast_BuiltinType_getBaseKind(bi1)]; +< return ast_getBuiltinQT(kind); +--- +> return ast_getBuiltinQT(conversion_checker_ConditionalOperatorResult[ast_BuiltinType_getBaseKind(bi2)][ast_BuiltinType_getBaseKind(bi1)]); +26242c26540 +< static ast_QualType conversion_checker_usual_arithmetic_conversion(const ast_BuiltinType* b1, const ast_BuiltinType* b2) +--- +> static ast_QualType conversion_checker_usual_arithmetic_conversion(const ast_BuiltinType* bi1, const ast_BuiltinType* bi2) +26244,26262c26542 +< ast_BuiltinKind k1 = ast_BuiltinType_getBaseKind(b1); +< ast_BuiltinKind k2 = ast_BuiltinType_getBaseKind(b2); +< switch (conversion_checker_UsualArithmeticConversions[k2][k1]) { +< case 0: +< return ast_getBuiltinQT(ast_BuiltinKind_Int32); +< case 1: +< return ast_getBuiltinQT(ast_BuiltinKind_UInt32); +< case 2: +< return ast_getBuiltinQT(ast_BuiltinKind_Int64); +< case 3: +< return ast_getBuiltinQT(ast_BuiltinKind_UInt64); +< case 4: +< return ast_getBuiltinQT(ast_BuiltinKind_Float32); +< case 5: +< return ast_getBuiltinQT(ast_BuiltinKind_Float64); +< case 6: +< break; +< } +< return ast_QualType_Invalid; +--- +> return ast_getBuiltinQT(conversion_checker_UsualArithmeticConversions[ast_BuiltinType_getBaseKind(bi1)][ast_BuiltinType_getBaseKind(bi2)]); +26370,26372d26649 +< w.width = (u8)(ast_getWordSize() * 8); +< w.is_signed = false; +< break; +26484c26761 +< .width = (u8)(ast_getWordSize() * 8), +--- +> .width = (u8)(ast_QualType_getAlignment(qt) * 8), +26510c26787 +< conversion_checker_Checker checker; +--- +> conversion_checker_Checker conv_checker; +26546,26547d26822 +< #define module_analyser_LHS 0x01 +< #define module_analyser_RHS 0x02 +26551c26826,26829 +< static void module_analyser_Analyser_check(module_analyser_Analyser* ma, ast_Module* mod); +--- +> static const char* module_analyser_Analyser_idx2name(const module_analyser_Analyser* ma, u32 name_idx); +> static const char* module_analyser_Analyser_getName(const module_analyser_Analyser* ma, const ast_Decl* d); +> static const char* module_analyser_Analyser_getFullName(const module_analyser_Analyser* ma, const ast_Decl* d); +> static void module_analyser_Analyser_checkModule(module_analyser_Analyser* ma, ast_Module* mod); +26588,26618d26865 +< static const u32 module_analyser_Binop_lhs[29] = { +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_RHS, +< module_analyser_LHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS, +< module_analyser_LHS | module_analyser_RHS +< }; +26639c26886 +< { 8, 9, 0, 1, 8, 2, 2, 0, 0 }, +--- +> { 8, 9, 0, 2, 8, 2, 2, 0, 0 }, +26682d26928 +< static ast_QualType module_analyser_Analyser_analyseEnumMinMax(module_analyser_Analyser* ma, ast_BuiltinExpr* b); +26704c26950 +< static const char* module_analyser_get_format(ast_Expr* format, src_loc_SrcLoc* format_loc); +--- +> static const char* module_analyser_Analyser_get_format(module_analyser_Analyser* ma, ast_Expr* format, src_loc_SrcLoc* format_loc); +26706c26952 +< static void module_analyser_create_template_name(char* name, u32 size, const char* orig, u16 idx); +--- +> static void module_analyser_Analyser_create_template_name(module_analyser_Analyser* ma, char* name, u32 size, u32 orig, u16 idx); +26732c26978 +< static void module_analyser_get_best_match(const char* name1, size_t len1, ast_StructTypeDecl* s, size_t* best_dist, const char** result); +--- +> static void module_analyser_Analyser_get_best_match(module_analyser_Analyser* ma, const char* name1, size_t len1, ast_StructTypeDecl* s, size_t* best_dist, const char** result); +26738c26984 +< static void module_analyser_Analyser_analyseFunction(module_analyser_Analyser* ma, ast_FunctionDecl* fd); +--- +> static void module_analyser_Analyser_analyseFunction(module_analyser_Analyser* ma, ast_FunctionDecl* fd, bool full); +26789,26790c27035,27036 +< static void module_analyser_Analyser_analyseBreakStmt(module_analyser_Analyser* ma, ast_Stmt* s); +< static void module_analyser_Analyser_analyseContinueStmt(module_analyser_Analyser* ma, ast_Stmt* s); +--- +> static module_analyser_FlowBits module_analyser_Analyser_analyseBreakStmt(module_analyser_Analyser* ma, ast_Stmt* s); +> static module_analyser_FlowBits module_analyser_Analyser_analyseContinueStmt(module_analyser_Analyser* ma, ast_Stmt* s); +26793c27039 +< static void module_analyser_Analyser_analyseGotoStmt(module_analyser_Analyser* ma, ast_Stmt* s); +--- +> static module_analyser_FlowBits module_analyser_Analyser_analyseGotoStmt(module_analyser_Analyser* ma, ast_Stmt* s); +26795c27041,27042 +< static ast_QualType module_analyser_Analyser_analyseCondition(module_analyser_Analyser* ma, ast_Stmt** s_ptr, bool check_assign); +--- +> static ast_QualType module_analyser_Analyser_analyseConditionDecl(module_analyser_Analyser* ma, ast_Stmt** s_ptr, const char* context); +> static ast_QualType module_analyser_Analyser_analyseCondition(module_analyser_Analyser* ma, ast_Stmt** s_ptr, const char* context, bool check_assign, bool check_bool); +26807a27055 +> static const char* module_analyser_Analyser_bitfieldDesc(module_analyser_Analyser* ma, u32 name_idx); +26811d27058 +< static ast_QualType module_analyser_Analyser_analyseSwitchDecl(module_analyser_Analyser* ma, ast_Stmt** s_ptr); +26820,26822c27067,27069 +< static ast_QualType module_analyser_Analyser_analyseStructMemberTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref); +< static ast_QualType module_analyser_Analyser_analyseUserTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref); +< static ast_QualType module_analyser_Analyser_analyseTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref); +--- +> static ast_QualType module_analyser_Analyser_analyseStructMemberFnTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref); +> static ast_QualType module_analyser_Analyser_analyseUserTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref, bool full); +> static ast_QualType module_analyser_Analyser_analyseTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref, bool full); +26841c27088 +< module_analyser_Analyser* ma = calloc(1, 576); +--- +> module_analyser_Analyser* ma = calloc(1, 336); +26843c27090 +< conversion_checker_Checker_init(&ma->checker, diags, builder); +--- +> conversion_checker_Checker_init(&ma->conv_checker, diags, builder); +26860c27107 +< module_analyser_Analyser* ma = calloc(1, 576); +--- +> module_analyser_Analyser* ma = calloc(1, 336); +26862c27109 +< conversion_checker_Checker_init(&ma->checker, org->diags, org->builder); +--- +> conversion_checker_Checker_init(&ma->conv_checker, org->diags, org->builder); +26887c27134,27149 +< static void module_analyser_Analyser_check(module_analyser_Analyser* ma, ast_Module* mod) +--- +> static const char* module_analyser_Analyser_idx2name(const module_analyser_Analyser* ma, u32 name_idx) +> { +> return string_pool_Pool_idx2str(ma->astPool, name_idx); +> } +> +> static const char* module_analyser_Analyser_getName(const module_analyser_Analyser* ma, const ast_Decl* d) +> { +> return string_pool_Pool_idx2str(ma->astPool, ast_Decl_getNameIdx(d)); +> } +> +> static const char* module_analyser_Analyser_getFullName(const module_analyser_Analyser* ma, const ast_Decl* d) +> { +> return ast_Decl_getFullName(d); +> } +> +> static void module_analyser_Analyser_checkModule(module_analyser_Analyser* ma, ast_Module* mod) +26928c27190 +< return calloc(1, 24); +--- +> return calloc(1, 16); +26990c27252 +< module_analyser_Analyser_error(ma, entry->loc, "module '%s' has no symbol '%s'", ast_Module_getName(ma->mod), ast_idx2name(name)); +--- +> module_analyser_Analyser_error(ma, entry->loc, "module '%s' has no symbol '%s'", ast_Module_getName(ma->mod), module_analyser_Analyser_idx2name(ma, name)); +26997,26998c27259,27260 +< module_analyser_Analyser_error(ma, entry->loc, "'%s' is not an incremental array", ast_idx2name(name)); +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(d), "'%s' is defined here", ast_idx2name(name)); +--- +> module_analyser_Analyser_error(ma, entry->loc, "'%s' is not an incremental array", module_analyser_Analyser_idx2name(ma, name)); +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(d), "'%s' is defined here", module_analyser_Analyser_idx2name(ma, name)); +27008,27009c27270,27271 +< module_analyser_Analyser_error(ma, entry->loc, "'%s' is not an incremental enum", ast_idx2name(name)); +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(d), "'%s' is defined here", ast_idx2name(name)); +--- +> module_analyser_Analyser_error(ma, entry->loc, "'%s' is not an incremental enum", module_analyser_Analyser_idx2name(ma, name)); +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(d), "'%s' is defined here", module_analyser_Analyser_idx2name(ma, name)); +27023,27024c27285,27286 +< module_analyser_Analyser_error(ma, entry->loc, "'%s' is not an incremental array/enum", ast_idx2name(name)); +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(d), "'%s' is defined here", ast_idx2name(name)); +--- +> module_analyser_Analyser_error(ma, entry->loc, "'%s' is not an incremental array/enum", module_analyser_Analyser_idx2name(ma, name)); +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(d), "'%s' is defined here", module_analyser_Analyser_idx2name(ma, name)); +27086c27348 +< scope_Scope* s = scope_create(ma->allmodules, ma->diags, ast_AST_getImports(a), ma->mod, ast_Module_getSymbols(ma->mod), !ma->warnings->no_unused_variable); +--- +> scope_Scope* s = scope_create(ma->allmodules, ma->diags, ma->astPool, ast_AST_getImports(a), ma->mod, ast_Module_getSymbols(ma->mod), !ma->warnings->no_unused_variable); +27119c27381 +< module_analyser_Analyser_error(ma, prefix->loc, "module '%s' has no symbol '%s'", ast_Module_getName(ma->mod), ast_Ref_getName(prefix)); +--- +> module_analyser_Analyser_error(ma, prefix->loc, "module '%s' has no symbol '%s'", ast_Module_getName(ma->mod), module_analyser_Analyser_idx2name(ma, ast_Ref_getNameIdx(prefix))); +27139c27401 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "redefinition of '%s'", ast_Decl_getFullName(d)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "redefinition of '%s'", module_analyser_Analyser_getFullName(ma, d)); +27148c27410 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(match), "member '%s' conflicts with type-function '%s'", ast_Decl_getName(match), ast_Decl_getFullName(d)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(match), "member '%s' conflicts with type-function '%s'", module_analyser_Analyser_getName(ma, match), module_analyser_Analyser_getFullName(ma, d)); +27184c27446 +< module_analyser_Analyser_analyseFunction(ma, (ast_FunctionDecl*)d); +--- +> module_analyser_Analyser_analyseFunction(ma, (ast_FunctionDecl*)d, true); +27272c27534 +< msg = string_pool_Pool_idx2str(ma->astPool, ast_StringLiteral_getTextIndex(s)); +--- +> msg = module_analyser_Analyser_idx2name(ma, ast_StringLiteral_getText(s)); +27324c27586 +< string_buffer_Buf_print(&buf, " %s ", ast_BinaryOpcode_str(opcode)); +--- +> string_buffer_Buf_print(&buf, " %s ", ast_BinaryOpcode__name[opcode]); +27350c27612 +< const char* name = ast_Decl_getName(d); +--- +> const char* name = module_analyser_Analyser_getName(ma, d); +27376c27638 +< res = module_analyser_Analyser_analyseTypeRef(ma, ref); +--- +> res = module_analyser_Analyser_analyseTypeRef(ma, ref, true); +27394c27656 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "array-type variable '%s' needs an explicit size or an initializer", ast_Decl_getFullName(d)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "array-type variable '%s' needs an explicit size or an initializer", module_analyser_Analyser_getFullName(ma, d)); +27410c27672 +< const char* filename = string_pool_Pool_idx2str(ma->astPool, embed->value.text); +--- +> const char* filename = module_analyser_Analyser_idx2name(ma, embed->value.text); +27426c27688 +< if (ast_Decl_isPublic(d)) ast_setTypePublicUsed(res); +--- +> if (ast_Decl_isPublic(d)) ast_QualType_setTypeUsedPublic(res); +27437c27699 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "constant variable '%s' must be initialized", ast_Decl_getFullName(d)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "constant variable '%s' must be initialized", module_analyser_Analyser_getFullName(ma, d)); +27471c27733 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(other), "circular declaration dependency '%s'", ast_Decl_getName(other)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(other), "circular declaration dependency '%s'", module_analyser_Analyser_getName(ma, other)); +27479c27741 +< ;//assert(ma->checkIndex <= module_analyser_MaxDepth); +--- +> ;//assert(ma->checkIndex < module_analyser_MaxDepth); +27579c27841 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(sub), "invalid operand type '%s' for binary expression '%s'", ast_QualType_diagName(qt), ast_BinaryOpcode_str(ast_BinaryOperator_getOpcode(b))); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(sub), "invalid operand type '%s' for binary expression '%s'", ast_QualType_diagName(qt), ast_BinaryOpcode__name[ast_BinaryOperator_getOpcode(b)]); +27933c28195 +< module_analyser_Analyser_error(ma, loc, "comparison of function '%s' will always be true", ast_Decl_getFullName(ast_FunctionDecl_asDecl(fd))); +--- +> module_analyser_Analyser_error(ma, loc, "comparison of function '%s' will always be true", module_analyser_Analyser_getFullName(ma, ast_FunctionDecl_asDecl(fd))); +27954c28216 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(sub), "operators '%s' and '%s' do not combine without parentheses", ast_BinaryOpcode_str(opcode), ast_BinaryOpcode_str(op1)); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(sub), "operators '%s' and '%s' do not combine without parentheses", ast_BinaryOpcode__name[opcode], ast_BinaryOpcode__name[op1]); +27968c28230 +< ast_QualType ltype = module_analyser_Analyser_analyseExpr(ma, ast_BinaryOperator_getLHS2(b), need_lhs_rvalue, module_analyser_Binop_lhs[opcode]); +--- +> ast_QualType ltype = module_analyser_Analyser_analyseExpr(ma, ast_BinaryOperator_getLHS2(b), need_lhs_rvalue, ast_BinaryOpcode__side[opcode]); +27992c28254 +< rtype = module_analyser_Analyser_analyseExpr(ma, ast_BinaryOperator_getRHS2(b), true, module_analyser_RHS); +--- +> rtype = module_analyser_Analyser_analyseExpr(ma, ast_BinaryOperator_getRHS2(b), true, ast_RHS); +28094,28096d28355 +< case ast_BuiltinExprKind_EnumMin: +< case ast_BuiltinExprKind_EnumMax: +< return module_analyser_Analyser_analyseEnumMinMax(ma, b); +28115c28374 +< qt = module_analyser_Analyser_analyseTypeRef(ma, ref); +--- +> qt = module_analyser_Analyser_analyseTypeRef(ma, ref, true); +28145c28404 +< ast_BuiltinExpr_setUValue(e, info.size); +--- +> ast_BuiltinExpr_setValue(e, info.size); +28154c28413 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, &inner, false, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, &inner, false, ast_RHS); +28163c28422 +< ast_BuiltinExpr_setUValue(b, ast_ArrayType_getSize(at)); +--- +> ast_BuiltinExpr_setValue(b, ast_ArrayType_getSize(at)); +28169c28428 +< ast_BuiltinExpr_setUValue(b, ast_EnumTypeDecl_getNumConstants(etd)); +--- +> ast_BuiltinExpr_setValue(b, ast_EnumTypeDecl_getNumConstants(etd)); +28176,28195d28434 +< static ast_QualType module_analyser_Analyser_analyseEnumMinMax(module_analyser_Analyser* ma, ast_BuiltinExpr* b) +< { +< ast_Expr* inner = ast_BuiltinExpr_getInner(b); +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, &inner, false, module_analyser_RHS); +< if (ast_QualType_isInvalid(qt)) return ast_QualType_Invalid; +< ast_EnumType* et = ast_QualType_getEnumTypeOrNil(qt); +< if (!et) { +< const char* kind = (ast_BuiltinExpr_getKind(b) == ast_BuiltinExprKind_EnumMin) ? "enum_min" : "enum_max"; +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(inner), "%s can only be used on enum types", kind); +< return ast_QualType_Invalid; +< } +< ast_EnumTypeDecl* etd = ast_EnumType_getDecl(et); +< u32 num = ast_EnumTypeDecl_getNumConstants(etd); +< ast_EnumConstantDecl** constants = ast_EnumTypeDecl_getConstants(etd); +< u32 index = 0; +< if (ast_BuiltinExpr_getKind(b) == ast_BuiltinExprKind_EnumMax) index = num - 1; +< ast_BuiltinExpr_setValue(b, ast_EnumConstantDecl_getValue(constants[index])); +< return ast_EnumTypeDecl_getImplType(etd); +< } +< +28200c28439 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, &inner, false, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, &inner, false, ast_RHS); +28219c28458 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, &inner, false, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, &inner, false, ast_RHS); +28232c28471 +< ast_QualType qptr = module_analyser_Analyser_analyseExpr(ma, pptr, false, module_analyser_RHS); +--- +> ast_QualType qptr = module_analyser_Analyser_analyseExpr(ma, pptr, false, ast_RHS); +28239c28478 +< if (!conversion_checker_Checker_check(&ma->checker, expectedType, qptr, pptr, ast_Expr_getLoc((*pptr)))) { +--- +> if (!conversion_checker_Checker_checkAssign(&ma->conv_checker, expectedType, qptr, pptr, ast_Expr_getLoc((*pptr)))) { +28285c28524 +< if (d) ast_BuiltinExpr_setUValue(b, ctx.base_offset); +--- +> if (d) ast_BuiltinExpr_setValue(b, ctx.base_offset); +28302c28541 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, func, true, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, func, true, ast_RHS); +28331c28570 +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(ast_FunctionDecl_asDecl(fd)), module_analyser_NoteDeclaredHere, ast_Decl_getFullName(ast_FunctionDecl_asDecl(fd))); +--- +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(ast_FunctionDecl_asDecl(fd)), module_analyser_NoteDeclaredHere, module_analyser_Analyser_getFullName(ma, ast_FunctionDecl_asDecl(fd))); +28338c28577 +< module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(e), ast_Expr_getRange(e), "function %s requires a template argument", ast_Decl_getFullName(ast_FunctionDecl_asDecl(fd))); +--- +> module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(e), ast_Expr_getRange(e), "function %s requires a template argument", module_analyser_Analyser_getFullName(ma, ast_FunctionDecl_asDecl(fd))); +28345c28584 +< module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(e), ast_Expr_getRange(e), "function %s is not a template function", ast_Decl_getFullName(ast_FunctionDecl_asDecl(fd))); +--- +> module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(e), ast_Expr_getRange(e), "function %s is not a template function", module_analyser_Analyser_getFullName(ma, ast_FunctionDecl_asDecl(fd))); +28351,28352c28590,28591 +< const char* msg = string_pool_Pool_idx2str(ma->astPool, deprecated->value.text); +< module_analyser_Analyser_warn(ma, ast_Expr_getLoc(origFn), "function %s is deprecated: %s", ast_Decl_getFullName(ast_FunctionDecl_asDecl(fd)), msg); +--- +> const char* msg = module_analyser_Analyser_idx2name(ma, deprecated->value.text); +> module_analyser_Analyser_warn(ma, ast_Expr_getLoc(origFn), "function %s is deprecated: %s", module_analyser_Analyser_getFullName(ma, ast_FunctionDecl_asDecl(fd)), msg); +28381,28382c28620,28622 +< module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(e), ast_Expr_getRange(e), "'%s' is a static type-function; use '%s()'", ast_Decl_getFullName(fdd), ast_Decl_getFullName(fdd)); +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(fdd), "'%s' is defined here", ast_Decl_getFullName(fdd)); +--- +> const char* full_name = module_analyser_Analyser_getFullName(ma, fdd); +> module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(e), ast_Expr_getRange(e), "'%s' is a static type-function; use '%s()'", full_name, full_name); +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(fdd), "'%s' is defined here", full_name); +28417c28657 +< bool ok = conversion_checker_Checker_check(&ma->checker, expectedType, baseType, e_ptr, loc); +--- +> bool ok = conversion_checker_Checker_checkAssign(&ma->conv_checker, expectedType, baseType, e_ptr, loc); +28449c28689 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(arg), "unexpected named argument '%s'", string_pool_Pool_idx2str(ma->astPool, arg_name_idx)); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(arg), "unexpected named argument '%s'", module_analyser_Analyser_idx2name(ma, arg_name_idx)); +28452c28692 +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(d), "expected argument '%s' instead", string_pool_Pool_idx2str(ma->astPool, param_name_idx)); +--- +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(d), "expected argument '%s' instead", module_analyser_Analyser_idx2name(ma, param_name_idx)); +28476c28716 +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(ast_FunctionDecl_asDecl(fd)), module_analyser_NoteDeclaredHere, ast_Decl_getFullName(ast_FunctionDecl_asDecl(fd))); +--- +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(ast_FunctionDecl_asDecl(fd)), module_analyser_NoteDeclaredHere, module_analyser_Analyser_getFullName(ma, ast_FunctionDecl_asDecl(fd))); +28485c28725 +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(ast_FunctionDecl_asDecl(fd)), module_analyser_NoteDeclaredHere, ast_Decl_getFullName(ast_FunctionDecl_asDecl(fd))); +--- +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(ast_FunctionDecl_asDecl(fd)), module_analyser_NoteDeclaredHere, module_analyser_Analyser_getFullName(ma, ast_FunctionDecl_asDecl(fd))); +28489c28729 +< ast_QualType callType = module_analyser_Analyser_analyseExpr(ma, &call_args[call_arg_index], true, module_analyser_RHS); +--- +> ast_QualType callType = module_analyser_Analyser_analyseExpr(ma, &call_args[call_arg_index], true, ast_RHS); +28591c28831,28836 +< if (width > 32) string_buffer_Buf_add1(fa->out, 'l'); +--- +> if (width > 32) { +> string_buffer_Buf_add1(fa->out, 'l'); +> if (ast_builder_Builder_getNativeLong(ma->builder) == ast_BuiltinKind_Int32) { +> string_buffer_Buf_add1(fa->out, 'l'); +> } +> } +28616c28861,28866 +< if (width > 32) string_buffer_Buf_add1(fa->out, 'l'); +--- +> if (width > 32) { +> string_buffer_Buf_add1(fa->out, 'l'); +> if (ast_builder_Builder_getNativeLong(ma->builder) == ast_BuiltinKind_Int32) { +> string_buffer_Buf_add1(fa->out, 'l'); +> } +> } +28712a28963 +> break; +28731c28982 +< static const char* module_analyser_get_format(ast_Expr* format, src_loc_SrcLoc* format_loc) +--- +> static const char* module_analyser_Analyser_get_format(module_analyser_Analyser* ma, ast_Expr* format, src_loc_SrcLoc* format_loc) +28743c28994 +< return ast_StringLiteral_getText(s); +--- +> return module_analyser_Analyser_idx2name(ma, ast_StringLiteral_getText(s)); +28783c29034 +< const char* format_text = module_analyser_get_format(format, &format_loc); +--- +> const char* format_text = module_analyser_Analyser_get_format(ma, format, &format_loc); +28822c29073 +< static void module_analyser_create_template_name(char* name, u32 size, const char* orig, u16 idx) +--- +> static void module_analyser_Analyser_create_template_name(module_analyser_Analyser* ma, char* name, u32 size, u32 orig, u16 idx) +28824c29075 +< snprintf(name, size, "%s_%d_", orig, idx); +--- +> snprintf(name, size, "%s_%d_", module_analyser_Analyser_idx2name(ma, orig), idx); +28837c29088 +< ast_QualType templateType = module_analyser_Analyser_analyseTypeRef(ma, template_arg); +--- +> ast_QualType templateType = module_analyser_Analyser_analyseTypeRef(ma, template_arg, true); +28859c29110 +< module_analyser_Analyser_analyseFunction(ma, instance); +--- +> module_analyser_Analyser_analyseFunction(ma, instance, true); +28865c29116 +< scope_Scope* tmpScope = scope_create(ma->allmodules, ma->diags, ast_AST_getImports(ast_Decl_getAST(d)), template_mod, ast_Module_getSymbols(template_mod), !ma->warnings->no_unused_variable); +--- +> scope_Scope* tmpScope = scope_create(ma->allmodules, ma->diags, ma->astPool, ast_AST_getImports(ast_Decl_getAST(d)), template_mod, ast_Module_getSymbols(template_mod), !ma->warnings->no_unused_variable); +28873c29124 +< module_analyser_create_template_name(name, 64, ast_Decl_getName(d), instance_idx); +--- +> module_analyser_Analyser_create_template_name(ma, name, 64, ast_Decl_getNameIdx(d), instance_idx); +28884c29135 +< ast_QualType result = module_analyser_Analyser_analyseExprInner(ma, e_ptr, module_analyser_RHS); +--- +> ast_QualType result = module_analyser_Analyser_analyseExprInner(ma, e_ptr, ast_RHS); +29021c29272 +< if (side & module_analyser_RHS || side == 0) { +--- +> if (side & ast_RHS || side == 0) { +29034c29285 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "public inline function using non-public %s '%s'", kind_str, ast_Decl_getFullName(d)); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "public inline function using non-public %s '%s'", kind_str, module_analyser_Analyser_getFullName(ma, d)); +29036c29287 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "public declaration using non-public %s '%s'", kind_str, ast_Decl_getFullName(d)); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "public declaration using non-public %s '%s'", kind_str, module_analyser_Analyser_getFullName(ma, d)); +29107c29358 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, ast_ConditionalOperator_getCond2(cond), true, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, ast_ConditionalOperator_getCond2(cond), true, ast_RHS); +29113,29114c29364,29365 +< ast_QualType lhs = module_analyser_Analyser_analyseExpr(ma, ast_ConditionalOperator_getLHS2(cond), true, module_analyser_RHS); +< ast_QualType rhs = module_analyser_Analyser_analyseExpr(ma, ast_ConditionalOperator_getRHS2(cond), true, module_analyser_RHS); +--- +> ast_QualType lhs = module_analyser_Analyser_analyseExpr(ma, ast_ConditionalOperator_getLHS2(cond), true, ast_RHS); +> ast_QualType rhs = module_analyser_Analyser_analyseExpr(ma, ast_ConditionalOperator_getRHS2(cond), true, ast_RHS); +29203c29454 +< module_analyser_Analyser_error(ma, loc, "cannot assign to read-only variable '%s'", ast_Decl_getFullName(ast_IdentifierExpr_getDecl(i))); +--- +> module_analyser_Analyser_error(ma, loc, "cannot assign to read-only variable '%s'", module_analyser_Analyser_getFullName(ma, ast_IdentifierExpr_getDecl(i))); +29253,29254c29504,29505 +< ast_QualType destType = module_analyser_Analyser_analyseTypeRef(ma, ref); +< ast_QualType srcType = module_analyser_Analyser_analyseExpr(ma, ast_ExplicitCastExpr_getInner2(c), true, module_analyser_RHS); +--- +> ast_QualType destType = module_analyser_Analyser_analyseTypeRef(ma, ref, true); +> ast_QualType srcType = module_analyser_Analyser_analyseExpr(ma, ast_ExplicitCastExpr_getInner2(c), true, ast_RHS); +29264c29515 +< if (!conversion_checker_Checker_checkCast(&ma->checker, destType, srcType, ast_TypeRef_getLoc(ref), ast_Expr_getLoc(inner))) return ast_QualType_Invalid; +--- +> if (!conversion_checker_Checker_checkCast(&ma->conv_checker, destType, srcType, ast_TypeRef_getLoc(ref), ast_Expr_getLoc(inner))) return ast_QualType_Invalid; +29273c29524 +< ast_QualType q = module_analyser_Analyser_analyseExpr(ma, ast_ArraySubscriptExpr_getBase2(sub), true, side | module_analyser_RHS); +--- +> ast_QualType q = module_analyser_Analyser_analyseExpr(ma, ast_ArraySubscriptExpr_getBase2(sub), true, side | ast_RHS); +29277c29528 +< if (side & module_analyser_LHS) { +--- +> if (side & ast_LHS) { +29304c29555 +< qidx = module_analyser_Analyser_analyseExpr(ma, ast_ArraySubscriptExpr_getIndex2(sub), true, module_analyser_RHS); +--- +> qidx = module_analyser_Analyser_analyseExpr(ma, ast_ArraySubscriptExpr_getIndex2(sub), true, ast_RHS); +29318,29319c29569 +< ast_QualType q2 = ast_Expr_getType(orig); +< ast_ArrayType* at = ast_QualType_getArrayTypeOrNil(q2); +--- +> ast_ArrayType* at = ast_QualType_getArrayTypeOrNil(otype); +29326c29576 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(index), "array out-of-bounds access [%lu] in array of [%u]", idx, size); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(index), "array out-of-bounds access [%llu] in array of [%u]", idx, size); +29377c29627 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, e_ptr, true, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, e_ptr, true, ast_RHS); +29403c29653 +< static void module_analyser_get_best_match(const char* name1, size_t len1, ast_StructTypeDecl* s, size_t* best_dist, const char** result) +--- +> static void module_analyser_Analyser_get_best_match(module_analyser_Analyser* ma, const char* name1, size_t len1, ast_StructTypeDecl* s, size_t* best_dist, const char** result) +29409,29411c29659,29661 +< const char* name2 = ast_Decl_getName(m); +< if (name2 == NULL) { +< module_analyser_get_best_match(name1, len1, (ast_StructTypeDecl*)m, best_dist, result); +--- +> u32 name_idx = ast_Decl_getNameIdx(m); +> if (!name_idx) { +> module_analyser_Analyser_get_best_match(ma, name1, len1, (ast_StructTypeDecl*)m, best_dist, result); +29412a29663 +> const char* name2 = module_analyser_Analyser_idx2name(ma, name_idx); +29426c29677 +< const char* name1 = ast_idx2name(name_idx); +--- +> const char* name1 = module_analyser_Analyser_idx2name(ma, name_idx); +29430c29681 +< module_analyser_get_best_match(name1, len1, s, &dist, &result); +--- +> module_analyser_Analyser_get_best_match(ma, name1, len1, s, &dist, &result); +29434c29685 +< module_analyser_Analyser_error(ma, loc, "no member named '%s' in %s '%s'; did you mean '%s'?", ast_idx2name(name_idx), ast_StructTypeDecl_isStruct(s) ? "struct" : "union", ast_Decl_getFullName(ast_StructTypeDecl_asDecl(s)), result); +--- +> module_analyser_Analyser_error(ma, loc, "no member named '%s' in %s '%s'; did you mean '%s'?", name1, ast_StructTypeDecl_isStruct(s) ? "struct" : "union", module_analyser_Analyser_getFullName(ma, ast_StructTypeDecl_asDecl(s)), result); +29436c29687 +< module_analyser_Analyser_error(ma, loc, "no member named '%s' in %s '%s'", ast_idx2name(name_idx), ast_StructTypeDecl_isStruct(s) ? "struct" : "union", ast_Decl_getFullName(ast_StructTypeDecl_asDecl(s))); +--- +> module_analyser_Analyser_error(ma, loc, "no member named '%s' in %s '%s'", name1, ast_StructTypeDecl_isStruct(s) ? "struct" : "union", module_analyser_Analyser_getFullName(ma, ast_StructTypeDecl_asDecl(s))); +29471c29722 +< ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref); +--- +> ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref, true); +29483c29734 +< ast_setTypePublicUsed(res); +--- +> ast_QualType_setTypeUsedPublic(res); +29502c29753 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "redefinition of '%s'", ast_VarDecl_getName(prev)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "redefinition of '%s'", module_analyser_Analyser_idx2name(ma, name_idx2)); +29507c29758 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "enum-associated name '%s' is reserved", ast_VarDecl_getName(vd)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "enum-associated name '%s' is reserved", module_analyser_Analyser_idx2name(ma, name_idx)); +29512,29513c29763,29764 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(fn_decl), "redefinition of '%s'", ast_Decl_getFullName(fn_decl)); +< module_analyser_Analyser_note(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "previous definition is here"); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "redefinition of '%s'", module_analyser_Analyser_getFullName(ma, fn_decl)); +> module_analyser_Analyser_note(ma, ast_Decl_getLoc(fn_decl), "previous definition is here"); +29574c29825 +< module_analyser_Analyser_error(ma, ast_InitListExpr_getEndLoc(ile), "missing initializer for enum-associated value '%s'", ast_Decl_getName(col_decl)); +--- +> module_analyser_Analyser_error(ma, ast_InitListExpr_getEndLoc(ile), "missing initializer for enum-associated value '%s'", module_analyser_Analyser_getName(ma, col_decl)); +29580c29831 +< static void module_analyser_Analyser_analyseFunction(module_analyser_Analyser* ma, ast_FunctionDecl* fd) +--- +> static void module_analyser_Analyser_analyseFunction(module_analyser_Analyser* ma, ast_FunctionDecl* fd, bool full) +29600c29851 +< ast_QualType qt = module_analyser_Analyser_analyseTypeRef(ma, rtype); +--- +> ast_QualType qt = module_analyser_Analyser_analyseTypeRef(ma, rtype, full); +29610c29861 +< if (is_public) ast_setTypePublicUsed(qt); +--- +> if (is_public) ast_QualType_setTypeUsedPublic(qt); +29619c29870 +< ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref); +--- +> ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref, full); +29630c29881 +< if (is_public) ast_setTypePublicUsed(res); +--- +> if (is_public) ast_QualType_setTypeUsedPublic(res); +29644,29651c29895,29904 +< if (ast_VarDecl_hasAttrAutoFile(vd) && !ast_TypeRef_isConstCharPtr(ref)) { +< module_analyser_Analyser_error(ma, ast_TypeRef_getLoc(ref), "attribute 'auto_file' requires a parameter of type 'const char*'"); +< } +< if (ast_VarDecl_hasAttrAutoLine(vd) && !ast_TypeRef_isU32(ref)) { +< module_analyser_Analyser_error(ma, ast_TypeRef_getLoc(ref), "attribute 'auto_line' requires a parameter of type 'u32'"); +< } +< if (ast_VarDecl_hasAttrAutoFunc(vd) && !ast_TypeRef_isConstCharPtr(ref)) { +< module_analyser_Analyser_error(ma, ast_TypeRef_getLoc(ref), "attribute 'auto_func' requires a parameter of type 'const char*'"); +--- +> if (ast_VarDecl_hasAutoAttr(vd)) { +> if (ast_VarDecl_hasAttrAutoFile(vd) && !ast_TypeRef_isConstCharPtr(ref)) { +> module_analyser_Analyser_error(ma, ast_TypeRef_getLoc(ref), "attribute 'auto_file' requires a parameter of type 'const char*'"); +> } +> if (ast_VarDecl_hasAttrAutoLine(vd) && !ast_TypeRef_isU32(ref)) { +> module_analyser_Analyser_error(ma, ast_TypeRef_getLoc(ref), "attribute 'auto_line' requires a parameter of type 'u32'"); +> } +> if (ast_VarDecl_hasAttrAutoFunc(vd) && !ast_TypeRef_isConstCharPtr(ref)) { +> module_analyser_Analyser_error(ma, ast_TypeRef_getLoc(ref), "attribute 'auto_func' requires a parameter of type 'const char*'"); +> } +29744c29997 +< scope_Scope* tmpScope = scope_create(ma->allmodules, ma->diags, ast_AST_getImports(ast_Decl_getAST(ast_FunctionDecl_asDecl(fd))), mod, ast_Module_getSymbols(mod), !ma->warnings->no_unused_variable); +--- +> scope_Scope* tmpScope = scope_create(ma->allmodules, ma->diags, ma->astPool, ast_AST_getImports(ast_Decl_getAST(ast_FunctionDecl_asDecl(fd))), mod, ast_Module_getSymbols(mod), !ma->warnings->no_unused_variable); +29790c30043 +< module_analyser_Analyser_warn(ma, ast_Decl_getLoc(p), "unused parameter '%s'", ast_Decl_getName(p)); +--- +> module_analyser_Analyser_warn(ma, ast_Decl_getLoc(p), "unused parameter '%s'", module_analyser_Analyser_getName(ma, p)); +29800c30053 +< module_analyser_Analyser_warn(ma, l->loc, "unused label '%s'", ast_idx2name(l->name_idx)); +--- +> module_analyser_Analyser_warn(ma, l->loc, "unused label '%s'", module_analyser_Analyser_idx2name(ma, l->name_idx)); +29801a30055 +> if (l->stmt && l->has_goto) ast_LabelStmt_setGoto(l->stmt); +29803c30057 +< module_analyser_Analyser_error(ma, l->loc, "use of undeclared label '%s'", ast_idx2name(l->name_idx)); +--- +> module_analyser_Analyser_error(ma, l->loc, "use of undeclared label '%s'", module_analyser_Analyser_idx2name(ma, l->name_idx)); +29881c30135 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, e_ptr, true, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, e_ptr, true, ast_RHS); +29883c30137 +< if (!conversion_checker_Checker_check(&ma->checker, expectedType, ast_Expr_getType(e), e_ptr, assignLoc)) return false; +--- +> if (!conversion_checker_Checker_checkAssign(&ma->conv_checker, expectedType, ast_Expr_getType(e), e_ptr, assignLoc)) return false; +29893c30147 +< ast_QualType res = module_analyser_Analyser_analyseExpr(ma, e_ptr, true, module_analyser_RHS); +--- +> ast_QualType res = module_analyser_Analyser_analyseExpr(ma, e_ptr, true, ast_RHS); +29907c30161 +< if (!conversion_checker_Checker_check(&ma->checker, expectedType, res, e_ptr, assignLoc)) return false; +--- +> if (!conversion_checker_Checker_checkAssign(&ma->conv_checker, expectedType, res, e_ptr, assignLoc)) return false; +30079c30333 +< module_analyser_Analyser_error(ma, loc, "array designator index '%lu' exceeds array upper bound '%lu'", *valp, size - 1); +--- +> module_analyser_Analyser_error(ma, loc, "array designator index '%llu' exceeds array upper bound '%llu'", *valp, size - 1); +30100c30354 +< module_analyser_Analyser_error(ma, loc, "array slice length '%lu' exceeds remaining length '%lu'", len, size - start_index); +--- +> module_analyser_Analyser_error(ma, loc, "array slice length '%llu' exceeds remaining length '%llu'", len, size - start_index); +30145c30399 +< module_analyser_Analyser_error(ma, loc, "array range designator start '%lu' is greater than end '%lu'", index_lo, index_hi); +--- +> module_analyser_Analyser_error(ma, loc, "array range designator start '%llu' is greater than end '%llu'", index_lo, index_hi); +30157c30411 +< module_analyser_Analyser_error(ma, loc, "array index %lu is too large", index_hi); +--- +> module_analyser_Analyser_error(ma, loc, "array index %llu is too large", index_hi); +30266c30520 +< if (!ctv_analyser_checkBitfield(ma->diags, fif->bitfield_width, fif->bitfield_signed, inner)) return false; +--- +> if (!ctv_analyser_checkBitfield(ma->diags, fif->bitfield_width, fif->bitfield_signed, inner)) goto out; +30307,30308c30561 +< const ast_StructMemberLayout* ml = &layout->members[member_idx]; +< while (ml->is_bitfield && ml->bitfield_width == 0 && member_idx < num_members) { +--- +> while (member_idx < num_members && layout->members[member_idx].is_bitfield && layout->members[member_idx].bitfield_width == 0) { +30310d30562 +< ml = &layout->members[member_idx]; +30315a30568 +> const ast_StructMemberLayout* ml = &layout->members[member_idx]; +30347c30600 +< u32 start = 0; +--- +> ast_Decl* d = NULL; +30356c30609,30624 +< start = 1; +--- +> } else { +> u32 name_idx = ast_MemberExpr_getNameIdx(m, 0); +> src_loc_SrcLoc loc = ast_MemberExpr_getLoc(m, 0); +> d = scope_Scope_find(ma->scope, name_idx, loc, ma->usedPublic); +> if (!d) { +> ma->has_error = true; +> return ast_QualType_Invalid; +> } +> if (!ast_Decl_isChecked(d)) { +> if (!module_analyser_Analyser_analyseGlobalDecl(ma, d)) return ast_QualType_Invalid; +> } +> baseType = ast_Decl_getType(d); +> valtype = module_analyser_decl2valtype(d); +> baseLoc = loc; +> ast_Decl_setUsed(d); +> ast_MemberExpr_setDecl(m, d, 0); +30358d30625 +< ast_Decl* d = NULL; +30360,30375c30627,30630 +< for (u32 i = start; i < 2; i++) { +< is_substruct = false; +< u32 name_idx = ast_MemberExpr_getNameIdx(m, i); +< src_loc_SrcLoc loc = ast_MemberExpr_getLoc(m, i); +< if (ast_QualType_isInvalid(baseType)) { +< d = scope_Scope_find(ma->scope, name_idx, loc, ma->usedPublic); +< if (!d) { +< ma->has_error = true; +< return ast_QualType_Invalid; +< } +< if (!ast_Decl_isChecked(d)) { +< if (!module_analyser_Analyser_analyseGlobalDecl(ma, d)) return ast_QualType_Invalid; +< } +< baseType = ast_Decl_getType(d); +< valtype = module_analyser_decl2valtype(d); +< } else { +--- +> { +> u32 name_idx = ast_MemberExpr_getNameIdx(m, 1); +> src_loc_SrcLoc loc = ast_MemberExpr_getLoc(m, 1); +> { +30435c30690 +< module_analyser_Analyser_error(ma, loc, "enum '%s' has no constant '%s'", ast_Decl_getFullName(d), name); +--- +> module_analyser_Analyser_error(ma, loc, "enum '%s' has no constant '%s'", module_analyser_Analyser_getFullName(ma, d), name); +30441c30696 +< module_analyser_Analyser_error(ma, loc, "circular definition using enum constant '%s'", ast_Decl_getName(d)); +--- +> module_analyser_Analyser_error(ma, loc, "circular definition using enum constant '%s'", module_analyser_Analyser_getName(ma, d)); +30448d30702 +< ck = (valtype == ast_ValType_NValue) ? ast_CallKind_StaticTypeFunc : ast_CallKind_TypeFunc; +30464c30718 +< module_analyser_Analyser_error(ma, loc, "enum '%s' has no function or associated value '%s'", ast_Decl_getFullName(d), name); +--- +> module_analyser_Analyser_error(ma, loc, "enum '%s' has no function or associated value '%s'", module_analyser_Analyser_getFullName(ma, d), name); +30483c30737 +< ast_MemberExpr_setDecl(m, vdd, i); +--- +> ast_MemberExpr_setDecl(m, vdd, 1); +30486c30740 +< ast_MemberExpr_setDecl(m, vdd, i); +--- +> ast_MemberExpr_setDecl(m, vdd, 1); +30489a30744,30746 +> ast_Decl* add = (ast_Decl*)ad; +> ast_Decl_setUsed(add); +> if (ast_Decl_isPublic(add)) ast_Decl_setUsedPublic(add); +30522,30527c30779,30780 +< if (i == 1) { +< if (side & module_analyser_RHS) ast_Decl_setUsed(d); +< } else { +< ast_Decl_setUsed(d); +< } +< ast_MemberExpr_setDecl(m, d, i); +--- +> if (side & ast_RHS) ast_Decl_setUsed(d); +> ast_MemberExpr_setDecl(m, d, 1); +30537c30790 +< if (side == module_analyser_RHS) ast_Expr_setRValue(e); +--- +> if (side == ast_RHS) ast_Expr_setRValue(e); +30695c30948 +< const char* func_name = ast_Decl_getFullName(ast_FunctionDecl_asDecl(ma->curFunction)); +--- +> const char* func_name = module_analyser_Analyser_getFullName(ma, ast_FunctionDecl_asDecl(ma->curFunction)); +30817,30819c31070,31071 +< module_analyser_Analyser_analyseBreakStmt(ma, s); +< scope_Scope_setUnreachable(ma->scope); +< return module_analyser_FlowBreak; +--- +> flow = module_analyser_Analyser_analyseBreakStmt(ma, s); +> break; +30821,30823c31073,31074 +< module_analyser_Analyser_analyseContinueStmt(ma, s); +< scope_Scope_setUnreachable(ma->scope); +< return module_analyser_FlowContinue; +--- +> flow = module_analyser_Analyser_analyseContinueStmt(ma, s); +> break; +30831,30833c31082,31083 +< module_analyser_Analyser_analyseGotoStmt(ma, s); +< scope_Scope_setUnreachable(ma->scope); +< return module_analyser_FlowGoto; +--- +> flow = module_analyser_Analyser_analyseGotoStmt(ma, s); +> break; +30853c31103 +< static void module_analyser_Analyser_analyseBreakStmt(module_analyser_Analyser* ma, ast_Stmt* s) +--- +> static module_analyser_FlowBits module_analyser_Analyser_analyseBreakStmt(module_analyser_Analyser* ma, ast_Stmt* s) +30856a31107 +> return module_analyser_FlowError; +30857a31109,31120 +> ast_BreakStmt* bs = (ast_BreakStmt*)s; +> if (ast_BreakStmt_hasName(bs)) { +> label_vector_Label* label = label_vector_LabelVector_find(&ma->labels, ast_BreakStmt_getName(bs)); +> if (label && label->can_break) { +> label->has_break = true; +> label->used = true; +> return module_analyser_FlowGoto; +> } +> module_analyser_Analyser_error(ma, ast_Stmt_getLoc(s), "'break' label does match an enclosing loop or switch statement"); +> return module_analyser_FlowError; +> } +> return module_analyser_FlowBreak; +30860c31123 +< static void module_analyser_Analyser_analyseContinueStmt(module_analyser_Analyser* ma, ast_Stmt* s) +--- +> static module_analyser_FlowBits module_analyser_Analyser_analyseContinueStmt(module_analyser_Analyser* ma, ast_Stmt* s) +30863a31127 +> return module_analyser_FlowError; +30864a31129,31140 +> ast_ContinueStmt* cs = (ast_ContinueStmt*)s; +> if (ast_ContinueStmt_hasName(cs)) { +> label_vector_Label* label = label_vector_LabelVector_find(&ma->labels, ast_ContinueStmt_getName(cs)); +> if (label && label->can_continue) { +> label->has_continue = true; +> label->used = true; +> return module_analyser_FlowGoto; +> } +> module_analyser_Analyser_error(ma, ast_Stmt_getLoc(s), "'continue' label does match an enclosing loop statement"); +> return module_analyser_FlowError; +> } +> return module_analyser_FlowContinue; +30879c31155 +< module_analyser_Analyser_error(ma, ast_Stmt_getLoc(s), "redefinition of label '%s'", ast_LabelStmt_getName(ls)); +--- +> module_analyser_Analyser_error(ma, ast_Stmt_getLoc(s), "redefinition of label '%s'", module_analyser_Analyser_idx2name(ma, name)); +30893a31170,31185 +> { +> ast_Stmt* st = ast_LabelStmt_getStmt(ls); +> if (st) { +> switch (ast_Stmt_getKind(st)) { +> case ast_StmtKind_For: +> case ast_StmtKind_While: +> lab.can_continue = true; +> fallthrough; +> case ast_StmtKind_Switch: +> lab.can_break = true; +> break; +> default: +> break; +> } +> } +> } +30898c31190,31204 +< return module_analyser_Analyser_analyseStmt(ma, lss, true); +--- +> module_analyser_FlowBits flow = module_analyser_Analyser_analyseStmt(ma, lss, true); +> label = label_vector_LabelVector_find(&ma->labels, name); +> if (label->has_break) { +> ast_LabelStmt_setUsed(ls); +> ast_LabelStmt_setBreak(ls); +> scope_Scope_setReachable(ma->scope); +> flow |= module_analyser_FlowNext; +> } +> if (label->has_continue) { +> ast_LabelStmt_setUsed(ls); +> ast_LabelStmt_setContinue(ls); +> } +> label->can_break = false; +> label->can_continue = false; +> return flow; +30901c31207 +< static void module_analyser_Analyser_analyseGotoStmt(module_analyser_Analyser* ma, ast_Stmt* s) +--- +> static module_analyser_FlowBits module_analyser_Analyser_analyseGotoStmt(module_analyser_Analyser* ma, ast_Stmt* s) +30907a31214 +> label->has_goto = true; +30914a31222 +> .has_goto = true, +30918a31227 +> return module_analyser_FlowGoto; +30935c31244 +< static ast_QualType module_analyser_Analyser_analyseCondition(module_analyser_Analyser* ma, ast_Stmt** s_ptr, bool check_assign) +--- +> static ast_QualType module_analyser_Analyser_analyseConditionDecl(module_analyser_Analyser* ma, ast_Stmt** s_ptr, const char* context) +30938,30946c31247,31258 +< if (ast_Stmt_isDecl(s)) { +< ast_QualType qt = module_analyser_Analyser_analyseDeclStmt(ma, s); +< if (ast_QualType_isValid(qt)) { +< ast_DeclStmt* ds = (ast_DeclStmt*)s; +< ast_VarDecl* vd = ast_DeclStmt_getDecl(ds, 0); +< if (!ast_VarDecl_getInit(vd)) { +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "variable declaration in condition must have an initializer"); +< return ast_QualType_Invalid; +< } +--- +> ;//assert(ast_Stmt_isDecl(s)); +> ast_QualType qt = module_analyser_Analyser_analyseDeclStmt(ma, s); +> if (ast_QualType_isValid(qt)) { +> ast_DeclStmt* ds = (ast_DeclStmt*)s; +> ast_VarDecl* vd = ast_DeclStmt_getDecl(ds, 0); +> if (ast_VarDecl_hasInitCall(vd)) { +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "variable declaration in %s cannot have an init call", context); +> return ast_QualType_Invalid; +> } +> if (!ast_VarDecl_hasInit(vd)) { +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "variable declaration in %s must have an initializer", context); +> return ast_QualType_Invalid; +30948c31260,31268 +< return qt; +--- +> } +> return qt; +> } +> +> static ast_QualType module_analyser_Analyser_analyseCondition(module_analyser_Analyser* ma, ast_Stmt** s_ptr, const char* context, bool check_assign, bool check_bool) +> { +> ast_Stmt* s = *s_ptr; +> if (ast_Stmt_isDecl(s)) { +> return module_analyser_Analyser_analyseConditionDecl(ma, s_ptr, context); +30951c31271 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, (ast_Expr**)s_ptr, true, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, (ast_Expr**)s_ptr, true, ast_RHS); +30953,30954c31273,31276 +< if (ast_QualType_isValid(qt)) conversion_checker_Checker_check(&ma->checker, ast_getBuiltinQT(ast_BuiltinKind_Bool), qt, (ast_Expr**)s_ptr, ast_Expr_getLoc(e)); +< e = (ast_Expr*)*s_ptr; +--- +> if (check_bool) { +> if (ast_QualType_isValid(qt)) conversion_checker_Checker_checkAssign(&ma->conv_checker, ast_getBuiltinQT(ast_BuiltinKind_Bool), qt, (ast_Expr**)s_ptr, ast_Expr_getLoc(e)); +> e = (ast_Expr*)*s_ptr; +> } +30966,30967c31288,31312 +< module_analyser_Analyser_analyseCondition(ma, ast_IfStmt_getCond2(i), true); +< if (ma->has_error) goto done; +--- +> if (ast_IfStmt_hasDecl(i)) { +> ast_QualType ct = module_analyser_Analyser_analyseConditionDecl(ma, ast_IfStmt_getDecl2(i), "'if' condition"); +> if (ast_QualType_isInvalid(ct)) { +> scope_Scope_exit(ma->scope, ma->has_error); +> return module_analyser_FlowNext | module_analyser_FlowError; +> } +> } +> ast_VarDecl* vd = NULL; +> ast_Expr** condp = ast_IfStmt_getCond2(i); +> if (!*condp) { +> ast_DeclStmt* ds = (ast_DeclStmt*)ast_IfStmt_getDecl(i); +> ;//assert(ds); +> vd = ast_DeclStmt_getDecl(ds, 0); +> *condp = ast_builder_Builder_actOnIdentifier(ma->builder, 0, ast_Decl_getNameIdx(ast_VarDecl_asDecl(vd)), 0); +> } +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, condp, true, ast_RHS); +> if (ast_QualType_isInvalid(qt)) goto done; +> if (vd) ast_Decl_clearUsed(ast_VarDecl_asDecl(vd)); +> ast_Expr* e = *condp; +> bool ok = conversion_checker_Checker_checkAssign(&ma->conv_checker, ast_getBuiltinQT(ast_BuiltinKind_Bool), qt, condp, ast_Expr_getLoc(e)); +> e = *condp; +> if (ast_Expr_isAssignment(e)) { +> module_analyser_Analyser_warn(ma, ast_Expr_getLoc(e), "using the result of an assignment as a condition without parentheses"); +> } +> if (!ok) goto done; +30972,30973c31317,31318 +< ast_Stmt** else_ = ast_IfStmt_getElse2(i); +< if (else_) { +--- +> ast_Stmt** else_stmt = ast_IfStmt_getElse2(i); +> if (else_stmt) { +30975c31320 +< flow2 = module_analyser_Analyser_analyseStmt(ma, else_, true); +--- +> flow2 = module_analyser_Analyser_analyseStmt(ma, else_stmt, true); +30991c31336 +< ast_QualType ct = module_analyser_Analyser_analyseCondition(ma, init, false); +--- +> ast_QualType ct = module_analyser_Analyser_analyseCondition(ma, init, "'for' init clause", false, false); +30996c31341 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, cond, true, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, cond, true, ast_RHS); +30998c31343 +< conversion_checker_Checker_check(&ma->checker, ast_getBuiltinQT(ast_BuiltinKind_Bool), qt, cond, ast_Expr_getLoc((*cond))); +--- +> conversion_checker_Checker_checkAssign(&ma->conv_checker, ast_getBuiltinQT(ast_BuiltinKind_Bool), qt, cond, ast_Expr_getLoc((*cond))); +31011c31356 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, cont, true, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, cont, true, ast_RHS); +31027,31028c31372,31373 +< module_analyser_Analyser_analyseCondition(ma, ast_WhileStmt_getCond2(w), true); +< if (ma->has_error) goto done; +--- +> ast_QualType ct = module_analyser_Analyser_analyseCondition(ma, ast_WhileStmt_getCond2(w), "'while' condition", true, true); +> if (ast_QualType_isInvalid(ct)) goto done; +31078c31423 +< ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref); +--- +> ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref, true); +31099c31444 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "constant variable '%s' must be initialized", ast_Decl_getName(d)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "constant variable '%s' must be initialized", module_analyser_Analyser_getName(ma, d)); +31110c31455 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "array-type variable '%s' needs an explicit size or an initializer", ast_Decl_getName(d)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "array-type variable '%s' needs an explicit size or an initializer", module_analyser_Analyser_getName(ma, d)); +31134c31479 +< side = module_analyser_LHS; +--- +> side = ast_LHS; +31137c31482 +< side = module_analyser_RHS; +--- +> side = ast_RHS; +31147c31492 +< ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, ast_AssertStmt_getInner2(a), true, module_analyser_RHS); +--- +> ast_QualType qt = module_analyser_Analyser_analyseExpr(ma, ast_AssertStmt_getInner2(a), true, ast_RHS); +31150c31495,31505 +< conversion_checker_Checker_check(&ma->checker, ast_getBuiltinQT(ast_BuiltinKind_Bool), qt, ast_AssertStmt_getInner2(a), ast_Expr_getLoc(inner)); +--- +> if (ast_Expr_isAssignment(inner)) { +> char tmp[128]; +> string_buffer_Buf buf; string_buffer_Buf_init(&buf, tmp, 128, true, false, 0); +> string_buffer_Buf* out = &buf; +> ast_BinaryOperator* b = (ast_BinaryOperator*)inner; +> module_analyser_encode_expression(out, ast_BinaryOperator_getLHS(b)); +> string_buffer_Buf_add(out, " == "); +> module_analyser_encode_expression(out, ast_BinaryOperator_getRHS(b)); +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(inner), "invalid assignment, did you mean 'assert(%s)'?", string_buffer_Buf_str(out)); +> } +> conversion_checker_Checker_checkAssign(&ma->conv_checker, ast_getBuiltinQT(ast_BuiltinKind_Bool), qt, ast_AssertStmt_getInner2(a), ast_Expr_getLoc(inner)); +31187c31542 +< qt = module_analyser_Analyser_analyseExpr(ma, ast_AssertStmt_getCall2(a), true, module_analyser_RHS); +--- +> qt = module_analyser_Analyser_analyseExpr(ma, ast_AssertStmt_getCall2(a), true, ast_RHS); +31223c31578 +< module_analyser_Analyser_error(ma, ast_Stmt_getLoc(s) + 6, "non-void function %s should return a value", ast_Decl_getName(ast_FunctionDecl_asDecl(ma->curFunction))); +--- +> module_analyser_Analyser_error(ma, ast_Stmt_getLoc(s) + 6, "non-void function %s should return a value", module_analyser_Analyser_getName(ma, ast_FunctionDecl_asDecl(ma->curFunction))); +31229c31584 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "void function %s should not return a value", ast_Decl_getName(ast_FunctionDecl_asDecl(ma->curFunction))); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "void function %s should not return a value", module_analyser_Analyser_getName(ma, ast_FunctionDecl_asDecl(ma->curFunction))); +31272a31628,31638 +> static const char* module_analyser_Analyser_bitfieldDesc(module_analyser_Analyser* ma, u32 name_idx) +> { +> if (name_idx) { +> static char bitfield_desc[64]; +> snprintf(bitfield_desc, 64, "bit-field '%s'", module_analyser_Analyser_idx2name(ma, name_idx)); +> return bitfield_desc; +> } else { +> return "unnamed bit-field"; +> } +> } +> +31288c31654 +< const char* name = ast_VarDecl_getName(vd); +--- +> u32 name_idx = ast_VarDecl_getNameIdx(vd); +31290,31291c31656 +< if (name) module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "bit-field '%s' has invalid type", name); +< else module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "unnamed bit-field has invalid type"); +--- +> module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "%s has invalid type", module_analyser_Analyser_bitfieldDesc(ma, name_idx)); +31302c31667 +< if (name) module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "zero width for bit-field '%s'", name); +--- +> if (name_idx) module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "zero width for %s", module_analyser_Analyser_bitfieldDesc(ma, name_idx)); +31304,31316c31669,31677 +< } +< if (value_type_Value_isNegative(&value)) { +< if (name) module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "bit-field '%s' has negative width", name); +< else module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "unnamed bit-field has negative width"); +< } +< u32 field_width = value_type_Value_as_u32(&value); +< ast_VarDecl_setBitfieldWidth(vd, (u8)field_width); +< u32 minimum_type_width = ast_QualType_getBitFieldWidth(qt, true); +< if (ast_QualType_isEnum(qt) && field_width < minimum_type_width) { +< if (name) { +< module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "bit-field '%s' has insufficient bits for enum '%s' (need %u bits)", name, ast_QualType_diagName(qt), minimum_type_width); +< } else { +< module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "unnamed bit-field has insufficient bits for enum '%s' (need %u bits)", ast_QualType_diagName(qt), minimum_type_width); +--- +> } else if (value_type_Value_isNegative(&value)) { +> module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "%s has negative width", module_analyser_Analyser_bitfieldDesc(ma, name_idx)); +> } else { +> u32 field_width = value_type_Value_as_u32(&value); +> ast_VarDecl_setBitfieldWidth(vd, (u8)field_width); +> u32 minimum_type_width = ast_QualType_getBitFieldWidth(qt, true); +> if (ast_QualType_isEnum(qt) && field_width < minimum_type_width) { +> module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "%s has insufficient bits for enum '%s' (need %u bits)", module_analyser_Analyser_bitfieldDesc(ma, name_idx), ast_QualType_diagName(qt), minimum_type_width); +> return; +31318,31324c31679,31681 +< return; +< } +< if (field_width > type_width) { +< if (name) { +< module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "width of bit-field '%s' (%u bits) exceeds the width of its type (%u bit%s)", name, field_width, type_width, type_width > 1 ? "s" : ""); +< } else { +< module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "width of unnamed bit-field (%u bits) exceeds the width of its type (%u bit%s)", field_width, type_width, type_width > 1 ? "s" : ""); +--- +> if (field_width > type_width) { +> module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(bitfield), ast_Expr_getRange(bitfield), "width of %s (%u bits) exceeds the width of its type (%u bit%s)", module_analyser_Analyser_bitfieldDesc(ma, name_idx), field_width, type_width, type_width > 1 ? "s" : ""); +> return; +31326d31682 +< return; +31330c31686,31687 +< } else if (ast_Decl_isStructType(member)) { +--- +> } else { +> ;//assert(ast_Decl_isStructType(member)); +31347c31704 +< ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref); +--- +> ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref, true); +31360,31361c31717,31727 +< ast_Decl_setType(ast_VarDecl_asDecl(v), res); +< if (ma->usedPublic) ast_setTypePublicUsed(res); +--- +> ast_Decl* d = (ast_Decl*)v; +> ast_Decl_setType(d, res); +> if (ma->usedPublic) ast_QualType_setTypeUsedPublic(res); +> if (ast_Decl_hasAttr(d)) { +> if (ast_VarDecl_hasAttrWeak(v)) { +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "attribute 'weak' cannot be applied to struct members"); +> } +> if (ast_Decl_isExported(d)) { +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(d), "attribute 'export' cannot be applied to struct members"); +> } +> } +31380c31746 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(member), "duplicate struct/union member '%s'", ast_Decl_getName(member)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(member), "duplicate struct/union member '%s'", module_analyser_Analyser_idx2name(ma, name_idx)); +31394,31409d31759 +< static ast_QualType module_analyser_Analyser_analyseSwitchDecl(module_analyser_Analyser* ma, ast_Stmt** s_ptr) +< { +< ast_Stmt* s = *s_ptr; +< ;//assert(ast_Stmt_isDecl(s)); +< ast_QualType qt = module_analyser_Analyser_analyseDeclStmt(ma, s); +< if (ast_QualType_isValid(qt)) { +< ast_DeclStmt* ds = (ast_DeclStmt*)s; +< ast_VarDecl* vd = ast_DeclStmt_getDecl(ds, 0); +< if (!ast_VarDecl_getInit(vd)) { +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(ast_VarDecl_asDecl(vd)), "variable declaration in 'switch' expression must have an initializer"); +< return ast_QualType_Invalid; +< } +< } +< return qt; +< } +< +31419c31769 +< ast_QualType ct = module_analyser_Analyser_analyseSwitchDecl(ma, declp); +--- +> ast_QualType ct = module_analyser_Analyser_analyseConditionDecl(ma, declp, "'switch' expression"); +31433c31783 +< ast_QualType ct = module_analyser_Analyser_analyseExpr(ma, condp, true, module_analyser_RHS); +--- +> ast_QualType ct = module_analyser_Analyser_analyseExpr(ma, condp, true, ast_RHS); +31497c31847 +< string_buffer_Buf_add(out, ast_Decl_getName(ast_EnumConstantDecl_asDecl(ecd[i]))); +--- +> string_buffer_Buf_add(out, module_analyser_Analyser_getName(ma, ast_EnumConstantDecl_asDecl(ecd[i]))); +31526c31876 +< const char* str = ast_StringLiteral_getText(lit); +--- +> const char* str = module_analyser_Analyser_idx2name(ma, ast_StringLiteral_getText(lit)); +31528c31878 +< u8 slen = (ast_StringLiteral_getSize(lit) - 1) & 0xFF; +--- +> u8 slen = ast_StringLiteral_getLength(lit) & 0xFF; +31554c31904 +< ct = module_analyser_Analyser_analyseExpr(ma, &call, true, module_analyser_RHS); +--- +> ct = module_analyser_Analyser_analyseExpr(ma, &call, true, ast_RHS); +31557c31907 +< if (ast_SwitchStmt_hasCond(sw)) { +--- +> if (ast_SwitchStmt_hasSourceCond(sw)) { +31639c31989 +< module_analyser_Analyser_error(ma, loc, "enum constant '%s' does not come after '%s'", ast_idx2name(rhs_name_idx), ast_idx2name(lhs_name_idx)); +--- +> module_analyser_Analyser_error(ma, loc, "enum constant '%s' does not come after '%s'", module_analyser_Analyser_idx2name(ma, rhs_name_idx), module_analyser_Analyser_idx2name(ma, lhs_name_idx)); +31652c32002 +< module_analyser_Analyser_error(ma, loc, "duplicate case value '%s'", ast_Decl_getName(d)); +--- +> module_analyser_Analyser_error(ma, loc, "duplicate case value '%s'", module_analyser_Analyser_getName(ma, d)); +31696c32046 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(cond), "condition is not a constant of enum type '%s'", ast_Decl_getFullName(ast_EnumTypeDecl_asDecl(etd))); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(cond), "condition is not a constant of enum type '%s'", module_analyser_Analyser_getFullName(ma, ast_EnumTypeDecl_asDecl(etd))); +31722c32072 +< u32 len = ast_StringLiteral_getSize(lit) - 1; +--- +> u32 len = ast_StringLiteral_getLength(lit); +31727c32077,32078 +< if (memchr(ast_StringLiteral_getText(lit), 0, len)) { +--- +> index = ast_StringLiteral_getText(lit); +> if (memchr(module_analyser_Analyser_idx2name(ma, index), 0, len)) { +31731d32081 +< index = ast_StringLiteral_getTextIndex(lit); +31772,31773c32122,32124 +< *name_idxp = ast_IdentifierExpr_getNameIdx(id); +< ast_EnumConstantDecl* ecd = ast_EnumTypeDecl_findConstant(etd, *name_idxp); +--- +> u32 name_idx = ast_IdentifierExpr_getNameIdx(id); +> *name_idxp = name_idx; +> ast_EnumConstantDecl* ecd = ast_EnumTypeDecl_findConstant(etd, name_idx); +31775c32126 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "enum '%s' has no constant '%s'", ast_Decl_getFullName(ast_EnumTypeDecl_asDecl(etd)), ast_IdentifierExpr_getName(id)); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "enum '%s' has no constant '%s'", module_analyser_Analyser_getFullName(ma, ast_EnumTypeDecl_asDecl(etd)), module_analyser_Analyser_idx2name(ma, name_idx)); +31793c32144 +< module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "duplicate case value '%s'", ast_IdentifierExpr_getName(id)); +--- +> module_analyser_Analyser_error(ma, ast_Expr_getLoc(e), "duplicate case value '%s'", module_analyser_Analyser_idx2name(ma, name_idx)); +31806c32157 +< module_analyser_Analyser_analyseFunction(ma, fd); +--- +> module_analyser_Analyser_analyseFunction(ma, fd, false); +31813c32164 +< ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref); +--- +> ast_QualType res = module_analyser_Analyser_analyseTypeRef(ma, ref, true); +31845c32196 +< module_analyser_Analyser_error(ma, ast_Decl_getLoc(cd), "duplicate enum constant '%s'", ast_idx2name(name_idx)); +--- +> module_analyser_Analyser_error(ma, ast_Decl_getLoc(cd), "duplicate enum constant '%s'", module_analyser_Analyser_idx2name(ma, name_idx)); +31889c32240 +< static ast_QualType module_analyser_Analyser_analyseStructMemberTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref) +--- +> static ast_QualType module_analyser_Analyser_analyseStructMemberFnTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref) +31895c32246 +< module_analyser_Analyser_analyseFunction(ma, fd); +--- +> module_analyser_Analyser_analyseFunction(ma, fd, false); +31900c32251 +< static ast_QualType module_analyser_Analyser_analyseUserTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref) +--- +> static ast_QualType module_analyser_Analyser_analyseUserTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref, bool full) +31928c32279 +< module_analyser_Analyser_error(ma, user->loc, "public inline function using non-public type '%s'", ast_Decl_getFullName(d)); +--- +> module_analyser_Analyser_error(ma, user->loc, "public inline function using non-public type '%s'", module_analyser_Analyser_getFullName(ma, d)); +31930c32281 +< module_analyser_Analyser_error(ma, user->loc, "public declaration using non-public type '%s'", ast_Decl_getFullName(d)); +--- +> module_analyser_Analyser_error(ma, user->loc, "public declaration using non-public type '%s'", module_analyser_Analyser_getFullName(ma, d)); +31939c32290 +< bool full = !ast_TypeRef_isPointer(ref); +--- +> full &= !ast_TypeRef_isPointer(ref); +31941,31946c32292,32297 +< if (full && state == ast_DeclCheckState_InProgress) { +< module_analyser_Analyser_error(ma, user->loc, "circular declaration"); +< return ast_QualType_Invalid; +< } +< if (full && state != ast_DeclCheckState_Checked) { +< module_analyser_Analyser_analyseGlobalDecl(ma, d); +--- +> if (full) { +> if (state == ast_DeclCheckState_InProgress) { +> module_analyser_Analyser_error(ma, user->loc, "circular declaration"); +> return ast_QualType_Invalid; +> } +> if (state != ast_DeclCheckState_Checked) module_analyser_Analyser_analyseGlobalDecl(ma, d); +31954c32305 +< static ast_QualType module_analyser_Analyser_analyseTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref) +--- +> static ast_QualType module_analyser_Analyser_analyseTypeRef(module_analyser_Analyser* ma, ast_TypeRef* ref, bool full) +31969c32320 +< base = module_analyser_Analyser_analyseUserTypeRef(ma, ref); +--- +> base = module_analyser_Analyser_analyseUserTypeRef(ma, ref, full); +31974c32325 +< base = module_analyser_Analyser_analyseStructMemberTypeRef(ma, ref); +--- +> base = module_analyser_Analyser_analyseStructMemberFnTypeRef(ma, ref); +32042a32394,32397 +> if (!value_type_Value_checkRange(&value, 0, u32_max)) { +> module_analyser_Analyser_errorRange(ma, ast_Expr_getLoc(sizeExpr), ast_Expr_getRange(sizeExpr), "array size '%s' is too large", value_type_Value_str(&value)); +> return ast_QualType_Invalid; +> } +32070c32425 +< base = module_analyser_Analyser_analyseUserTypeRef(ma, ref); +--- +> base = module_analyser_Analyser_analyseUserTypeRef(ma, ref, true); +32137c32492 +< side |= module_analyser_LHS; +--- +> side |= ast_LHS; +32141c32496 +< side |= module_analyser_LHS; +--- +> side |= ast_LHS; +32148c32503 +< side |= module_analyser_RHS; +--- +> side |= ast_RHS; +32432,32433c32787,32788 +< ast_Module** copy = malloc(count * 8); +< memcpy(copy, orig, count * 8); +--- +> ast_Module** copy = malloc(count * 4); +> memcpy(copy, orig, count * 4); +32615,32616c32970 +< bool console_timing; +< bool console_debug; +--- +> console_Config* console_config; +32626c32980 +< static plugin_mgr_Mgr* plugin_mgr_create(string_pool_Pool* auxPool, bool console_timing, bool console_debug, bool no_plugins); +--- +> static plugin_mgr_Mgr* plugin_mgr_create(string_pool_Pool* auxPool, console_Config* console_config, bool no_plugins); +32642c32996 +< static plugin_mgr_Mgr* plugin_mgr_create(string_pool_Pool* auxPool, bool console_timing, bool console_debug, bool no_plugins) +--- +> static plugin_mgr_Mgr* plugin_mgr_create(string_pool_Pool* auxPool, console_Config* console_config, bool no_plugins) +32644c32998 +< plugin_mgr_Mgr* m = calloc(1, 312); +--- +> plugin_mgr_Mgr* m = calloc(1, 296); +32646,32647c33000 +< m->console_timing = console_timing; +< m->console_debug = console_debug; +--- +> m->console_config = console_config; +32680c33033 +< plugin_mgr_Plugin* plugins2 = malloc(m->plugin_max * 32); +--- +> plugin_mgr_Plugin* plugins2 = malloc(m->plugin_max * 20); +32682c33035 +< memcpy(plugins2, m->plugins, m->plugin_count * 32); +--- +> memcpy(plugins2, m->plugins, m->plugin_count * 20); +32756c33109 +< p.arg = p.functions->load(string_pool_Pool_idx2str(m->auxPool, options), m->console_timing, m->console_debug); +--- +> p.arg = p.functions->load(string_pool_Pool_idx2str(m->auxPool, options), m->console_config); +32868a33222 +> bool m32; +32894,32895c33248,33261 +< "char", "i8", "i16", "int", "i64", "u8", "u16", "u32", +< "u64", "float", "double", "ssize_t", "size_t", "bool" +--- +> [ast_BuiltinKind_Bool] = "bool", +> [ast_BuiltinKind_Char] = "char", +> [ast_BuiltinKind_Int8] = "i8", +> [ast_BuiltinKind_Int16] = "i16", +> [ast_BuiltinKind_Int32] = "int", +> [ast_BuiltinKind_Int64] = "i64", +> [ast_BuiltinKind_UInt8] = "u8", +> [ast_BuiltinKind_UInt16] = "u16", +> [ast_BuiltinKind_UInt32] = "u32", +> [ast_BuiltinKind_UInt64] = "u64", +> [ast_BuiltinKind_Float32] = "float", +> [ast_BuiltinKind_Float64] = "double", +> [ast_BuiltinKind_ISize] = "ssize_t", +> [ast_BuiltinKind_USize] = "size_t" +32944a33311 +> static const char* c_generator_Generator_idx2name(const c_generator_Generator* gen, u32 name_idx); +32949a33317 +> static void c_generator_Generator_emitName(c_generator_Generator* gen, string_buffer_Buf* out, const ast_Decl* d); +32951c33319 +< static void c_generator_Generator_emitCNameMod(c_generator_Generator* _arg0, string_buffer_Buf* out, const ast_Decl* d, ast_Module* mod); +--- +> static void c_generator_Generator_emitCNameMod(c_generator_Generator* gen, string_buffer_Buf* out, const ast_Decl* d, ast_Module* mod); +32959a33328 +> static void c_generator_Generator_emitFunctionParam(c_generator_Generator* gen, string_buffer_Buf* out, ast_QualType qt, u32 name_idx, u32 arg_num); +32969c33338 +< static void c_generator_Generator_emitSectionAttr(c_generator_Generator* gen, string_buffer_Buf* out, const char* name); +--- +> static void c_generator_Generator_emitSectionAttr(c_generator_Generator* gen, string_buffer_Buf* out, u32 name_idx); +33005c33374 +< static void c_generator_generate(string_pool_Pool* astPool, string_pool_Pool* auxPool, const char* target, build_target_Kind kind, const char* output_dir, diagnostics_Diags* diags, source_mgr_SourceMgr* sm, const build_file_Info* build_info, const target_info_Info* targetInfo, component_List* comps, ast_Decl* mainFunc, string_list_List* asm_files, bool enable_asserts, bool fast_build, bool asan, bool msan, bool ubsan, bool test_mode, bool trace_calls); +--- +> static void c_generator_generate(string_pool_Pool* astPool, string_pool_Pool* auxPool, const char* target, build_target_Kind kind, const char* output_dir, diagnostics_Diags* diags, source_mgr_SourceMgr* sm, const build_file_Info* build_info, const target_info_Info* targetInfo, component_List* comps, ast_Decl* mainFunc, string_list_List* asm_files, bool enable_asserts, bool fast_build, bool asan, bool msan, bool ubsan, bool m32, bool test_mode, bool trace_calls); +33030c33399 +< static const char c_generator_C2_types_header[635] = "// WARNING: this file is auto-generated by the C2 compiler.\n" +--- +> static const char c_generator_C2_types_header[633] = "// WARNING: this file is auto-generated by the C2 compiler.\n" +33039c33408 +< "#define to_container(type, member, ptr) ((type *)((char *)(ptr)-offsetof(type, member)))\n\n" +--- +> "#define to_container(type, member, ptr) ((type*)((char*)(ptr)-offsetof(type, member)))\n\n" +33057a33427,33429 +> static void c_generator_Generator_emitWhileStmt(c_generator_Generator* gen, string_buffer_Buf* out, ast_WhileStmt* w, u32 indent, ast_LabelStmt* ls); +> static void c_generator_Generator_emitForStmt(c_generator_Generator* gen, string_buffer_Buf* out, ast_ForStmt* f, u32 indent, ast_LabelStmt* ls); +> static void c_generator_Generator_emitLoopBody(c_generator_Generator* gen, string_buffer_Buf* out, ast_Stmt* body, u32 indent, u32 break_name, u32 continue_name); +33061c33433 +< static void c_generator_Generator_emitSwitchStmt(c_generator_Generator* gen, string_buffer_Buf* out, ast_SwitchStmt* sw, u32 indent); +--- +> static void c_generator_Generator_emitSwitchStmt(c_generator_Generator* gen, string_buffer_Buf* out, ast_SwitchStmt* sw, u32 indent, ast_LabelStmt* ls); +33086c33458 +< c_generator_Fragment* f = malloc(24); +--- +> c_generator_Fragment* f = malloc(12); +33101a33474,33478 +> static const char* c_generator_Generator_idx2name(const c_generator_Generator* gen, u32 name_idx) +> { +> return string_pool_Pool_idx2str(gen->astPool, name_idx); +> } +> +33139a33517,33521 +> static void c_generator_Generator_emitName(c_generator_Generator* gen, string_buffer_Buf* out, const ast_Decl* d) +> { +> string_buffer_Buf_add(out, c_generator_Generator_idx2name(gen, ast_Decl_getNameIdx(d))); +> } +> +33145c33527 +< static void c_generator_Generator_emitCNameMod(c_generator_Generator* _arg0, string_buffer_Buf* out, const ast_Decl* d, ast_Module* mod) +--- +> static void c_generator_Generator_emitCNameMod(c_generator_Generator* gen, string_buffer_Buf* out, const ast_Decl* d, ast_Module* mod) +33147c33529 +< if (!ast_Decl_getName(d)) return; +--- +> if (!ast_Decl_getNameIdx(d)) return; +33149c33531 +< const char* cname = ast_Decl_getCName(d); +--- +> u32 cname = ast_Decl_getCName(d); +33151c33533 +< string_buffer_Buf_add(out, cname); +--- +> string_buffer_Buf_add(out, c_generator_Generator_idx2name(gen, cname)); +33160c33542 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +33171c33553 +< string_buffer_Buf_add(out, ast_idx2name(prefix->name_idx)); +--- +> string_buffer_Buf_add(out, c_generator_Generator_idx2name(gen, prefix->name_idx)); +33178c33560,33561 +< string_buffer_Buf_add(out, ast_EnumType_getName(et)); +--- +> ast_EnumTypeDecl* etd = ast_EnumType_getDecl(et); +> c_generator_Generator_emitName(gen, out, ast_EnumTypeDecl_asDecl(etd)); +33181c33564 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +33189c33572 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +33216c33599 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +33218c33601 +< string_buffer_Buf_add(out, ast_Decl_getName(ast_EnumConstantDecl_asDecl(ecd))); +--- +> c_generator_Generator_emitName(gen, out, ast_EnumConstantDecl_asDecl(ecd)); +33372c33755 +< c_generator_Generator_gen_member_type_func(gen, fd, out, ast_Decl_getName(d)); +--- +> c_generator_Generator_gen_member_type_func(gen, fd, out, c_generator_Generator_idx2name(gen, ast_Decl_getNameIdx(d))); +33382c33765 +< if (ast_Decl_getNameIdx(d)) string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +33423c33806 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +33428a33812,33834 +> static void c_generator_Generator_emitFunctionParam(c_generator_Generator* gen, string_buffer_Buf* out, ast_QualType qt, u32 name_idx, u32 arg_num) +> { +> char temp[16]; +> const char* name; +> if (name_idx) { +> name = c_generator_Generator_idx2name(gen, name_idx); +> } else { +> snprintf(temp, 16, "_arg%u", arg_num); +> name = temp; +> } +> if (ast_QualType_isFunction(qt)) { +> ast_FunctionType* ft = ast_QualType_getFunctionType(qt); +> ast_FunctionDecl* fd = ast_FunctionType_getDecl(ft); +> if (ast_FunctionDecl_isParam(fd)) { +> c_generator_Generator_gen_member_type_func(gen, fd, out, name); +> return; +> } +> } +> c_generator_Generator_emitTypePre(gen, out, qt, false); +> string_buffer_Buf_space(out); +> string_buffer_Buf_add(out, name); +> } +> +33442d33847 +< ast_Decl* arg = (ast_Decl*)params[i]; +33444,33448c33849,33850 +< c_generator_Generator_emitTypePre(gen, out, ast_Decl_getType(arg), false); +< const char* name = ast_Decl_getName(arg); +< string_buffer_Buf_space(out); +< if (name) string_buffer_Buf_add(out, name); +< else string_buffer_Buf_print(out, "_arg%u", i); +--- +> ast_Decl* arg = (ast_Decl*)params[i]; +> c_generator_Generator_emitFunctionParam(gen, out, ast_Decl_getType(arg), ast_Decl_getNameIdx(arg), i); +33489,33490c33891,33892 +< const char* cname = ast_Decl_getCName(d); +< if (cname && c_generator_is_c_type(cname)) return; +--- +> u32 cname = ast_Decl_getCName(d); +> if (cname && c_generator_is_c_type(c_generator_Generator_idx2name(gen, cname))) return; +33533c33935 +< const char* cdef = ast_Decl_getCDef(d); +--- +> u32 cdef = ast_Decl_getCDef(d); +33535c33937 +< string_buffer_Buf_add(out, cdef); +--- +> string_buffer_Buf_add(out, c_generator_Generator_idx2name(gen, cdef)); +33545c33947 +< const char* section = ast_Decl_getSection(d); +--- +> u32 section = ast_Decl_getSection(d); +33603c34005 +< static void c_generator_Generator_emitSectionAttr(c_generator_Generator* gen, string_buffer_Buf* out, const char* name) +--- +> static void c_generator_Generator_emitSectionAttr(c_generator_Generator* gen, string_buffer_Buf* out, u32 name_idx) +33605c34007 +< string_buffer_Buf_print(out, "__attribute__((section(\"%s\")))", name); +--- +> string_buffer_Buf_print(out, "__attribute__((section(\"%s\")))", c_generator_Generator_idx2name(gen, name_idx)); +33628c34030 +< string_buffer_Buf_print(gen->header, "#include \"%s.h\"\n", ast_Decl_getName(d)); +--- +> string_buffer_Buf_print(gen->header, "#include \"%s.h\"\n", c_generator_Generator_idx2name(gen, name_idx)); +33639c34041 +< string_buffer_Buf_print(gen->out, "#include \"%s.h\"\n", ast_Decl_getName(d)); +--- +> string_buffer_Buf_print(gen->out, "#include \"%s.h\"\n", c_generator_Generator_idx2name(gen, name_idx)); +33706,33707c34108,34114 +< case ast_DeclKind_EnumConstant: +< console_warn("TODO gen enum %d", ast_Decl_isGenerated(d)); +--- +> case ast_DeclKind_EnumConstant: { +> c_generator_Fragment* f = c_generator_Generator_getFragment(gen); +> ast_QualType qt = ast_Decl_getType(d); +> ast_EnumType* et = ast_QualType_getEnumTypeOrNil(qt); +> ast_EnumTypeDecl* etd = ast_EnumType_getDecl(et); +> c_generator_Generator_emitEnumType(gen, f->buf, (ast_Decl*)etd); +> c_generator_Generator_addFragment(gen, f, ast_Decl_isPublic(d)); +33708a34116 +> } +33780c34188 +< const char* section = ast_Decl_getSection(d); +--- +> u32 section = ast_Decl_getSection(d); +33817d34224 +< ast_Decl* argx = (ast_Decl*)params[i]; +33819,33836c34226,34227 +< char temp[8]; +< const char* name = ast_Decl_getName(argx); +< if (!name) { +< snprintf(temp, 8, "_arg%u", i); +< name = temp; +< } +< ast_QualType qt = ast_Decl_getType(argx); +< if (ast_QualType_isFunction(qt)) { +< ast_FunctionType* ft = ast_QualType_getFunctionType(qt); +< ast_FunctionDecl* fd2 = ast_FunctionType_getDecl(ft); +< if (ast_FunctionDecl_isParam(fd2)) { +< c_generator_Generator_gen_member_type_func(gen, fd2, out, name); +< continue; +< } +< } +< c_generator_Generator_emitTypePre(gen, out, qt, false); +< string_buffer_Buf_space(out); +< string_buffer_Buf_add(out, name); +--- +> ast_Decl* arg = (ast_Decl*)params[i]; +> c_generator_Generator_emitFunctionParam(gen, out, ast_Decl_getType(arg), ast_Decl_getNameIdx(arg), i); +33885c34276 +< string_buffer_Buf_print(gen->header, "#include \"%s.h\"\n", ast_Decl_getName(d)); +--- +> string_buffer_Buf_print(gen->header, "#include \"%s.h\"\n", c_generator_Generator_idx2name(gen, name_idx)); +34099c34490 +< memset(gen, 0, 432); +--- +> memset(gen, 0, 252); +34143c34534 +< static void c_generator_generate(string_pool_Pool* astPool, string_pool_Pool* auxPool, const char* target, build_target_Kind kind, const char* output_dir, diagnostics_Diags* diags, source_mgr_SourceMgr* sm, const build_file_Info* build_info, const target_info_Info* targetInfo, component_List* comps, ast_Decl* mainFunc, string_list_List* asm_files, bool enable_asserts, bool fast_build, bool asan, bool msan, bool ubsan, bool test_mode, bool trace_calls) +--- +> static void c_generator_generate(string_pool_Pool* astPool, string_pool_Pool* auxPool, const char* target, build_target_Kind kind, const char* output_dir, diagnostics_Diags* diags, source_mgr_SourceMgr* sm, const build_file_Info* build_info, const target_info_Info* targetInfo, component_List* comps, ast_Decl* mainFunc, string_list_List* asm_files, bool enable_asserts, bool fast_build, bool asan, bool msan, bool ubsan, bool m32, bool test_mode, bool trace_calls) +34156a34548 +> gen.m32 = m32; +34220c34612 +< if (ast_getWordSize() == 4) { +--- +> if (gen->targetInfo->longWidth == 32) { +34222,34224c34614 +< "typedef unsigned long long u64;\n" +< "typedef signed long ssize_t;\n" +< "typedef unsigned long size_t;\n"); +--- +> "typedef unsigned long long u64;\n"); +34227,34229c34617,34624 +< "typedef unsigned long u64;\n" +< "typedef signed long ssize_t;\n" +< "typedef unsigned long size_t;\n"); +--- +> "typedef unsigned long u64;\n"); +> } +> if (gen->targetInfo->ptrWidth == 32) { +> string_buffer_Buf_add(out, "typedef signed int ssize_t;\n" +> "typedef unsigned int size_t;\n"); +> } else { +> string_buffer_Buf_add(out, "typedef signed long long ssize_t;\n" +> "typedef unsigned long long size_t;\n"); +34499,34500c34894,34895 +< const char* p = ast_idx2name(ast_StringLiteral_getTextIndex(s)); +< u32 len = ast_StringLiteral_getSize(s) - 1; +--- +> const char* p = c_generator_Generator_idx2name(gen, ast_StringLiteral_getText(s)); +> u32 len = ast_StringLiteral_getLength(s); +34508d34902 +< string_buffer_Buf_add1(out, '"'); +34510d34903 +< string_buffer_Buf_add1(out, '"'); +34517d34909 +< string_buffer_Buf_add1(out, '"'); +34519d34910 +< string_buffer_Buf_add1(out, '"'); +34535c34926 +< string_buffer_Buf_print(out, "0x%lx", mask); +--- +> string_buffer_Buf_print(out, "0x%llx", mask); +34603c34994 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +34624c35015 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +34680,34692c35071,35078 +< case ast_BuiltinExprKind_Sizeof: { +< value_type_Value v = ast_BuiltinExpr_getValue(b); +< string_buffer_Buf_print(out, "%s", value_type_Value_str(&v)); +< break; +< } +< case ast_BuiltinExprKind_Elemsof: { +< value_type_Value v = ast_BuiltinExpr_getValue(b); +< string_buffer_Buf_print(out, "%s", value_type_Value_str(&v)); +< break; +< } +< case ast_BuiltinExprKind_EnumMin: { +< value_type_Value v = ast_BuiltinExpr_getValue(b); +< string_buffer_Buf_print(out, "%s", value_type_Value_str(&v)); +--- +> case ast_BuiltinExprKind_Sizeof: +> if (ast_BuiltinExpr_useLiteral(b)) { +> string_buffer_Buf_add(out, "sizeof("); +> c_generator_Generator_emitExpr(gen, out, ast_BuiltinExpr_getInner(b)); +> string_buffer_Buf_rparen(out); +> } else { +> string_buffer_Buf_print(out, "%llu", ast_BuiltinExpr_getValue(b)); +> } +34694,34697c35080,35087 +< } +< case ast_BuiltinExprKind_EnumMax: { +< value_type_Value v = ast_BuiltinExpr_getValue(b); +< string_buffer_Buf_print(out, "%s", value_type_Value_str(&v)); +--- +> case ast_BuiltinExprKind_Elemsof: +> if (ast_BuiltinExpr_useLiteral(b)) { +> string_buffer_Buf_add(out, "ARRAY_SIZE("); +> c_generator_Generator_emitExpr(gen, out, ast_BuiltinExpr_getInner(b)); +> string_buffer_Buf_rparen(out); +> } else { +> string_buffer_Buf_print(out, "%llu", ast_BuiltinExpr_getValue(b)); +> } +34699,34702c35089,35098 +< } +< case ast_BuiltinExprKind_OffsetOf: { +< value_type_Value v = ast_BuiltinExpr_getValue(b); +< string_buffer_Buf_print(out, "%s", value_type_Value_str(&v)); +--- +> case ast_BuiltinExprKind_OffsetOf: +> if (ast_BuiltinExpr_useLiteral(b)) { +> string_buffer_Buf_add(out, "offsetof("); +> c_generator_Generator_emitExpr(gen, out, ast_BuiltinExpr_getInner(b)); +> string_buffer_Buf_add(out, ", "); +> c_generator_Generator_emitExpr(gen, out, ast_BuiltinExpr_getOffsetOfMember(b)); +> string_buffer_Buf_rparen(out); +> } else { +> string_buffer_Buf_print(out, "%llu", ast_BuiltinExpr_getValue(b)); +> } +34704d35099 +< } +34840a35236,35239 +> if (gen->m32) { +> string_buffer_Buf_add(out, "CFLAGS+=-m32\n"); +> string_buffer_Buf_add(out, "LDFLAGS+=-m32\n"); +> } +34991c35390 +< string_buffer_Buf_add(out, ast_Decl_getName(d)); +--- +> c_generator_Generator_emitName(gen, out, d); +35031,35032c35430 +< ast_Stmt* cond = ast_IfStmt_getCond(i); +< bool is_decl = ast_Stmt_isDecl(cond); +--- +> bool is_decl = ast_IfStmt_hasDecl(i); +35036c35434 +< c_generator_Generator_emitStmt(gen, out, cond, indent, true); +--- +> c_generator_Generator_emitStmt(gen, out, ast_IfStmt_getDecl(i), indent, true); +35038,35045d35435 +< string_buffer_Buf_add(out, "if ("); +< ast_DeclStmt* ds = (ast_DeclStmt*)cond; +< ast_VarDecl* vd = ast_DeclStmt_getDecl(ds, 0); +< string_buffer_Buf_add(out, ast_Decl_getName(ast_VarDecl_asDecl(vd))); +< } else { +< ;//assert(ast_Stmt_isExpr(cond)); +< string_buffer_Buf_add(out, "if ("); +< c_generator_Generator_emitExpr(gen, out, (ast_Expr*)cond); +35046a35437,35438 +> string_buffer_Buf_add(out, "if ("); +> c_generator_Generator_emitExpr(gen, out, ast_IfStmt_getCond(i)); +35068,35099c35460,35461 +< case ast_StmtKind_While: { +< ast_WhileStmt* w = (ast_WhileStmt*)s; +< ast_Stmt* cond = ast_WhileStmt_getCond(w); +< bool is_decl = ast_Stmt_isDecl(cond); +< if (is_decl) { +< string_buffer_Buf_add(out, "{\n"); +< indent++; +< ast_DeclStmt* ds = (ast_DeclStmt*)cond; +< ast_VarDecl* vd = ast_DeclStmt_getDecl(ds, 0); +< string_buffer_Buf_indent(out, indent); +< c_generator_Generator_emitVarDecl(gen, vd, out, false, true); +< string_buffer_Buf_add(out, ";\n"); +< string_buffer_Buf_indent(out, indent); +< string_buffer_Buf_add(out, "while (("); +< string_buffer_Buf_add(out, ast_Decl_getName(ast_VarDecl_asDecl(vd))); +< string_buffer_Buf_add(out, " = "); +< ast_Expr* ie = ast_VarDecl_getInit(vd); +< ;//assert(ie); +< c_generator_Generator_emitExpr(gen, out, ie); +< string_buffer_Buf_add(out, ")) "); +< } else { +< ;//assert(ast_Stmt_isExpr(cond)); +< string_buffer_Buf_add(out, "while ("); +< c_generator_Generator_emitExpr(gen, out, (ast_Expr*)cond); +< string_buffer_Buf_add(out, ") "); +< } +< c_generator_Generator_emitStmt(gen, out, ast_WhileStmt_getBody(w), indent, true); +< if (is_decl) { +< indent--; +< string_buffer_Buf_indent(out, indent); +< string_buffer_Buf_add(out, "}\n"); +< } +--- +> case ast_StmtKind_While: +> c_generator_Generator_emitWhileStmt(gen, out, (ast_WhileStmt*)s, indent, NULL); +35101,35121c35463,35464 +< } +< case ast_StmtKind_For: { +< ast_ForStmt* f = (ast_ForStmt*)s; +< string_buffer_Buf_add(out, "for ("); +< ast_Stmt* initStmt = ast_ForStmt_getInit(f); +< if (initStmt) { +< c_generator_Generator_emitStmt(gen, out, initStmt, 0, false); +< } +< string_buffer_Buf_add1(out, ';'); +< if (ast_ForStmt_getCond(f)) { +< string_buffer_Buf_space(out); +< c_generator_Generator_emitExpr(gen, out, ast_ForStmt_getCond(f)); +< } +< string_buffer_Buf_add1(out, ';'); +< ast_Expr* cont = ast_ForStmt_getCont(f); +< if (cont) { +< string_buffer_Buf_space(out); +< c_generator_Generator_emitExpr(gen, out, cont); +< } +< string_buffer_Buf_add(out, ") "); +< c_generator_Generator_emitStmt(gen, out, ast_ForStmt_getBody(f), indent, true); +--- +> case ast_StmtKind_For: +> c_generator_Generator_emitForStmt(gen, out, (ast_ForStmt*)s, indent, NULL); +35123d35465 +< } +35125c35467 +< c_generator_Generator_emitSwitchStmt(gen, out, (ast_SwitchStmt*)s, indent); +--- +> c_generator_Generator_emitSwitchStmt(gen, out, (ast_SwitchStmt*)s, indent, NULL); +35127,35128c35469,35472 +< case ast_StmtKind_Break: +< string_buffer_Buf_add(out, "break;\n"); +--- +> case ast_StmtKind_Break: { +> ast_BreakStmt* bs = (ast_BreakStmt*)s; +> if (ast_BreakStmt_hasName(bs)) string_buffer_Buf_print(out, "goto break__%s;\n", c_generator_Generator_idx2name(gen, ast_BreakStmt_getName(bs))); +> else string_buffer_Buf_add(out, "break;\n"); +35130,35131c35474,35478 +< case ast_StmtKind_Continue: +< string_buffer_Buf_add(out, "continue;\n"); +--- +> } +> case ast_StmtKind_Continue: { +> ast_ContinueStmt* cs = (ast_ContinueStmt*)s; +> if (ast_ContinueStmt_hasName(cs)) string_buffer_Buf_print(out, "goto continue__%s;\n", c_generator_Generator_idx2name(gen, ast_ContinueStmt_getName(cs))); +> else string_buffer_Buf_add(out, "continue;\n"); +35132a35480 +> } +35140,35143c35488,35513 +< string_buffer_Buf_add(out, ast_LabelStmt_getName(ls)); +< string_buffer_Buf_add1(out, ':'); +< if (!stmt || ast_Stmt_isDecl(stmt)) { +< string_buffer_Buf_add1(out, ';'); +--- +> if (ast_LabelStmt_hasGoto(ls)) { +> string_buffer_Buf_add(out, c_generator_Generator_idx2name(gen, ast_LabelStmt_getNameIdx(ls))); +> string_buffer_Buf_add1(out, ':'); +> if (!stmt || ast_Stmt_isDecl(stmt)) { +> string_buffer_Buf_add1(out, ';'); +> } +> string_buffer_Buf_newline(out); +> } +> if (stmt) { +> switch (ast_Stmt_getKind(stmt)) { +> case ast_StmtKind_For: +> string_buffer_Buf_indent(out, indent); +> c_generator_Generator_emitForStmt(gen, out, (ast_ForStmt*)stmt, indent, ls); +> break; +> case ast_StmtKind_While: +> string_buffer_Buf_indent(out, indent); +> c_generator_Generator_emitWhileStmt(gen, out, (ast_WhileStmt*)stmt, indent, ls); +> break; +> case ast_StmtKind_Switch: +> string_buffer_Buf_indent(out, indent); +> c_generator_Generator_emitSwitchStmt(gen, out, (ast_SwitchStmt*)stmt, indent, ls); +> break; +> default: +> c_generator_Generator_emitStmt(gen, out, stmt, indent, true); +> break; +> } +35145,35146d35514 +< string_buffer_Buf_newline(out); +< if (stmt) c_generator_Generator_emitStmt(gen, out, stmt, indent, true); +35152c35520 +< string_buffer_Buf_add(out, ast_GotoStmt_getName(g)); +--- +> string_buffer_Buf_add(out, c_generator_Generator_idx2name(gen, ast_GotoStmt_getNameIdx(g))); +35199a35568,35677 +> static void c_generator_Generator_emitWhileStmt(c_generator_Generator* gen, string_buffer_Buf* out, ast_WhileStmt* w, u32 indent, ast_LabelStmt* ls) +> { +> u32 break_name = 0; +> u32 continue_name = 0; +> if (ls) { +> if (ast_LabelStmt_hasBreak(ls)) break_name = ast_LabelStmt_getNameIdx(ls); +> if (ast_LabelStmt_hasContinue(ls)) continue_name = ast_LabelStmt_getNameIdx(ls); +> } +> ast_Stmt* cond = ast_WhileStmt_getCond(w); +> bool is_decl = ast_Stmt_isDecl(cond); +> if (is_decl || break_name) { +> string_buffer_Buf_add(out, "{\n"); +> indent++; +> string_buffer_Buf_indent(out, indent); +> } +> if (is_decl) { +> ast_DeclStmt* ds = (ast_DeclStmt*)cond; +> ast_VarDecl* vd = ast_DeclStmt_getDecl(ds, 0); +> c_generator_Generator_emitVarDecl(gen, vd, out, false, true); +> string_buffer_Buf_add(out, ";\n"); +> string_buffer_Buf_indent(out, indent); +> string_buffer_Buf_add(out, "while (("); +> c_generator_Generator_emitName(gen, out, ast_VarDecl_asDecl(vd)); +> string_buffer_Buf_add(out, " = "); +> ast_Expr* ie = ast_VarDecl_getInit(vd); +> ;//assert(ie); +> c_generator_Generator_emitExpr(gen, out, ie); +> string_buffer_Buf_add(out, ")) "); +> } else { +> ;//assert(ast_Stmt_isExpr(cond)); +> string_buffer_Buf_add(out, "while ("); +> c_generator_Generator_emitExpr(gen, out, (ast_Expr*)cond); +> string_buffer_Buf_add(out, ") "); +> } +> c_generator_Generator_emitLoopBody(gen, out, ast_WhileStmt_getBody(w), indent, break_name, continue_name); +> if (is_decl || break_name) { +> indent--; +> string_buffer_Buf_indent(out, indent); +> string_buffer_Buf_add(out, "}\n"); +> } +> } +> +> static void c_generator_Generator_emitForStmt(c_generator_Generator* gen, string_buffer_Buf* out, ast_ForStmt* f, u32 indent, ast_LabelStmt* ls) +> { +> u32 break_name = 0; +> u32 continue_name = 0; +> if (ls) { +> if (ast_LabelStmt_hasBreak(ls)) break_name = ast_LabelStmt_getNameIdx(ls); +> if (ast_LabelStmt_hasContinue(ls)) continue_name = ast_LabelStmt_getNameIdx(ls); +> } +> if (break_name) { +> string_buffer_Buf_add(out, "{\n"); +> indent++; +> string_buffer_Buf_indent(out, indent); +> } +> string_buffer_Buf_add(out, "for ("); +> ast_Stmt* initStmt = ast_ForStmt_getInit(f); +> if (initStmt) { +> c_generator_Generator_emitStmt(gen, out, initStmt, 0, false); +> } +> string_buffer_Buf_add1(out, ';'); +> if (ast_ForStmt_getCond(f)) { +> string_buffer_Buf_space(out); +> c_generator_Generator_emitExpr(gen, out, ast_ForStmt_getCond(f)); +> } +> string_buffer_Buf_add1(out, ';'); +> ast_Expr* cont = ast_ForStmt_getCont(f); +> if (cont) { +> string_buffer_Buf_space(out); +> c_generator_Generator_emitExpr(gen, out, cont); +> } +> string_buffer_Buf_add(out, ") "); +> c_generator_Generator_emitLoopBody(gen, out, ast_ForStmt_getBody(f), indent, break_name, continue_name); +> if (break_name) { +> indent--; +> string_buffer_Buf_indent(out, indent); +> string_buffer_Buf_add(out, "}\n"); +> } +> } +> +> static void c_generator_Generator_emitLoopBody(c_generator_Generator* gen, string_buffer_Buf* out, ast_Stmt* body, u32 indent, u32 break_name, u32 continue_name) +> { +> u32 count = 1; +> ast_Stmt** stmts = &body; +> if (ast_Stmt_isCompound(body)) { +> ast_CompoundStmt* c = (ast_CompoundStmt*)body; +> count = ast_CompoundStmt_getCount(c); +> stmts = ast_CompoundStmt_getStmts(c); +> } else { +> if (!continue_name) { +> c_generator_Generator_emitStmt(gen, out, body, indent, true); +> return; +> } +> } +> string_buffer_Buf_add(out, "{\n"); +> for (u32 i = 0; i < count; i++) { +> c_generator_Generator_emitStmt(gen, out, stmts[i], indent + 1, true); +> } +> if (continue_name) { +> string_buffer_Buf_indent(out, indent); +> string_buffer_Buf_print(out, "continue__%s:;\n", c_generator_Generator_idx2name(gen, continue_name)); +> } +> string_buffer_Buf_indent(out, indent); +> string_buffer_Buf_add(out, "}\n"); +> if (break_name) { +> string_buffer_Buf_indent(out, indent - 1); +> string_buffer_Buf_print(out, "break__%s:;\n", c_generator_Generator_idx2name(gen, break_name)); +> } +> } +> +35214c35692 +< string_buffer_Buf_print(out, "[%s] ", ast_idx2name(name)); +--- +> string_buffer_Buf_print(out, "[%s] ", c_generator_Generator_idx2name(gen, name)); +35263c35741 +< static void c_generator_Generator_emitSwitchStmt(c_generator_Generator* gen, string_buffer_Buf* out, ast_SwitchStmt* sw, u32 indent) +--- +> static void c_generator_Generator_emitSwitchStmt(c_generator_Generator* gen, string_buffer_Buf* out, ast_SwitchStmt* sw, u32 indent, ast_LabelStmt* ls) +35264a35743,35744 +> u32 break_name = 0; +> if (ls && ast_LabelStmt_hasBreak(ls)) break_name = ast_LabelStmt_getNameIdx(ls); +35266c35746 +< if (is_decl) { +--- +> if (is_decl || break_name) { +35269c35749 +< c_generator_Generator_emitStmt(gen, out, ast_SwitchStmt_getDecl(sw), indent, true); +--- +> if (is_decl) c_generator_Generator_emitStmt(gen, out, ast_SwitchStmt_getDecl(sw), indent, true); +35284c35764 +< if (is_decl) { +--- +> if (is_decl || break_name) { +35285a35766,35769 +> if (break_name) { +> string_buffer_Buf_indent(out, indent); +> string_buffer_Buf_print(out, "break__%s:;\n", c_generator_Generator_idx2name(gen, break_name)); +> } +35370c35854 +< memset(sl, 0, 48); +--- +> memset(sl, 0, 32); +35424c35908 +< char** strings2 = malloc(sl->string_capacity * 8); +--- +> char** strings2 = malloc(sl->string_capacity * 4); +35426c35910 +< memcpy(strings2, sl->strings, sl->string_count * 8); +--- +> memcpy(strings2, sl->strings, sl->string_count * 4); +35452c35936 +< string_buffer_Buf_add(out, "const char *c2_filenames[] = {\n"); +--- +> string_buffer_Buf_add(out, "const char* c2_filenames[] = {\n"); +35602c36086 +< const string_list_List* features; +--- +> const string_map_Map* features; +35676c36160 +< static c2_parser_Parser* c2_parser_create(source_mgr_SourceMgr* sm, diagnostics_Diags* diags, string_pool_Pool* pool, ast_builder_Builder* builder, const keywords_Info* kwinfo, const string_list_List* features, bool has_asserts); +--- +> static c2_parser_Parser* c2_parser_create(source_mgr_SourceMgr* sm, diagnostics_Diags* diags, string_pool_Pool* pool, ast_builder_Builder* builder, const keywords_Info* kwinfo, const string_map_Map* features, bool has_asserts); +35701c36185 +< static bool c2_parser_Parser_parseFunctionParams(c2_parser_Parser* p, ast_DeclList* params, bool is_public, bool accept_default); +--- +> static bool c2_parser_Parser_parseFunctionParams(c2_parser_Parser* p, ast_VarDeclList* params, bool is_public, bool accept_default); +35717c36201 +< static ast_BuiltinKind c2_parser_cTypeToBuiltinKind(c2_parser_CTypeKind kind); +--- +> static ast_BuiltinKind c2_parser_Parser_cTypeToBuiltinKind(c2_parser_Parser* p, c2_parser_CTypeKind kind); +35719c36203 +< static const c2_prec_Prec c2_parser_BinOpPrecLookup[135] = { +--- +> static const c2_prec_Prec c2_parser_BinOpPrecLookup[132] = { +35752c36236 +< static const ast_BinaryOpcode c2_parser_BinOpTokenLookup[135] = { +--- +> static const ast_BinaryOpcode c2_parser_BinOpTokenLookup[132] = { +35783c36267 +< static const u8 c2_parser_CastExprTokenLookup[135] = { +--- +> static const u8 c2_parser_CastExprTokenLookup[132] = { +35798,35821c36282,36302 +< [token_Kind_KW_cast] = 8, +< [token_Kind_KW_elemsof] = 9, +< [token_Kind_KW_enum_min] = 10, +< [token_Kind_KW_enum_max] = 10, +< [token_Kind_KW_false] = 11, +< [token_Kind_KW_true] = 11, +< [token_Kind_KW_nil] = 12, +< [token_Kind_KW_offsetof] = 13, +< [token_Kind_KW_sizeof] = 14, +< [token_Kind_KW_to_container] = 15, +< [token_Kind_KW_bool] = 16, +< [token_Kind_KW_char] = 16, +< [token_Kind_KW_i8] = 16, +< [token_Kind_KW_i16] = 16, +< [token_Kind_KW_i32] = 16, +< [token_Kind_KW_i64] = 16, +< [token_Kind_KW_u8] = 16, +< [token_Kind_KW_u16] = 16, +< [token_Kind_KW_u32] = 16, +< [token_Kind_KW_u64] = 16, +< [token_Kind_KW_isize] = 16, +< [token_Kind_KW_usize] = 16, +< [token_Kind_KW_f32] = 16, +< [token_Kind_KW_f64] = 16 +--- +> [token_Kind_KW_elemsof] = 8, +> [token_Kind_KW_false] = 9, +> [token_Kind_KW_true] = 9, +> [token_Kind_KW_nil] = 10, +> [token_Kind_KW_offsetof] = 11, +> [token_Kind_KW_sizeof] = 12, +> [token_Kind_KW_to_container] = 13, +> [token_Kind_KW_bool] = 14, +> [token_Kind_KW_char] = 14, +> [token_Kind_KW_i8] = 14, +> [token_Kind_KW_i16] = 14, +> [token_Kind_KW_i32] = 14, +> [token_Kind_KW_i64] = 14, +> [token_Kind_KW_u8] = 14, +> [token_Kind_KW_u16] = 14, +> [token_Kind_KW_u32] = 14, +> [token_Kind_KW_u64] = 14, +> [token_Kind_KW_isize] = 14, +> [token_Kind_KW_usize] = 14, +> [token_Kind_KW_f32] = 14, +> [token_Kind_KW_f64] = 14 +35842,35843d36322 +< static ast_Expr* c2_parser_Parser_parseExplicitCastExpr(c2_parser_Parser* p); +< static ast_Expr* c2_parser_Parser_parseEnumMinMax(c2_parser_Parser* p, bool is_min); +35879c36358 +< static void c2_parser_Parser_parseEnumAssocAttributes(c2_parser_Parser* p, ast_DeclList* params); +--- +> static void c2_parser_Parser_parseEnumAssocAttributes(c2_parser_Parser* p, ast_VarDeclList* params); +35886c36365 +< static c2_parser_Parser* c2_parser_create(source_mgr_SourceMgr* sm, diagnostics_Diags* diags, string_pool_Pool* pool, ast_builder_Builder* builder, const keywords_Info* kwinfo, const string_list_List* features, bool has_asserts) +--- +> static c2_parser_Parser* c2_parser_create(source_mgr_SourceMgr* sm, diagnostics_Diags* diags, string_pool_Pool* pool, ast_builder_Builder* builder, const keywords_Info* kwinfo, const string_map_Map* features, bool has_asserts) +35888c36367 +< c2_parser_Parser* p = calloc(1, 67392); +--- +> c2_parser_Parser* p = calloc(1, 67312); +35903c36382 +< p->stmt_lists = malloc(c2_parser_NumStmtLists * 48); +--- +> p->stmt_lists = malloc(c2_parser_NumStmtLists * 28); +36028c36507 +< c2_parser_Parser_errorAt(p, loc, "expected '%s'", token_Kind_str(kind)); +--- +> c2_parser_Parser_errorAt(p, loc, "expected '%s'", token_Kind__name[kind]); +36178c36657 +< c2_parser_Parser_error(p, "invalid keyword '%s' in extern C code", token_Kind_str(p->tok.kind)); +--- +> c2_parser_Parser_error(p, "invalid keyword '%s' in extern C code", token_Kind__name[p->tok.kind]); +36180c36659 +< c2_parser_Parser_error(p, "invalid '%s' definition in C2 code", token_Kind_str(p->tok.kind)); +--- +> c2_parser_Parser_error(p, "invalid '%s' definition in C2 code", token_Kind__name[p->tok.kind]); +36280c36759 +< ast_DeclList params; ast_DeclList_init(¶ms); +--- +> ast_VarDeclList params; ast_VarDeclList_init(¶ms); +36289c36768 +< f = ast_builder_Builder_actOnTemplateFunctionDecl(p->builder, func_name, func_loc, is_public, rtype, template_name, template_loc, (ast_VarDecl**)ast_DeclList_getDecls(¶ms), ast_DeclList_size(¶ms), is_variadic); +--- +> f = ast_builder_Builder_actOnTemplateFunctionDecl(p->builder, func_name, func_loc, is_public, rtype, template_name, template_loc, ast_VarDeclList_getData(¶ms), ast_VarDeclList_size(¶ms), is_variadic); +36291c36770 +< f = ast_builder_Builder_actOnFunctionDecl(p->builder, func_name, func_loc, is_public, rtype, prefix, (ast_VarDecl**)ast_DeclList_getDecls(¶ms), ast_DeclList_size(¶ms), is_variadic); +--- +> f = ast_builder_Builder_actOnFunctionDecl(p->builder, func_name, func_loc, is_public, rtype, prefix, ast_VarDeclList_getData(¶ms), ast_VarDeclList_size(¶ms), is_variadic); +36293c36772 +< ast_DeclList_free(¶ms); +--- +> ast_VarDeclList_free(¶ms); +36310c36789 +< static bool c2_parser_Parser_parseFunctionParams(c2_parser_Parser* p, ast_DeclList* params, bool is_public, bool accept_default) +--- +> static bool c2_parser_Parser_parseFunctionParams(c2_parser_Parser* p, ast_VarDeclList* params, bool is_public, bool accept_default) +36326c36805 +< ast_DeclList_add(params, ast_VarDecl_asDecl(decl)); +--- +> ast_VarDeclList_add(params, decl); +36341c36820 +< if (p->tok.kind == token_Kind_KW_local || p->tok.kind == token_Kind_KW_static || p->tok.kind == token_Kind_KW_tlocal) c2_parser_Parser_error(p, "keyword '%s' is not allowed here", token_Kind_str(p->tok.kind)); +--- +> if (p->tok.kind == token_Kind_KW_local || p->tok.kind == token_Kind_KW_static || p->tok.kind == token_Kind_KW_tlocal) c2_parser_Parser_error(p, "keyword '%s' is not allowed here", token_Kind__name[p->tok.kind]); +36347c36826 +< ast_DeclList params; ast_DeclList_init(¶ms); +--- +> ast_VarDeclList params; ast_VarDeclList_init(¶ms); +36349,36350c36828,36829 +< ast_Decl* fd = ast_builder_Builder_actOnFunctionType(p->builder, &rtype, (ast_VarDecl**)ast_DeclList_getDecls(¶ms), ast_DeclList_size(¶ms), is_variadic, ast_DefKind_Param); +< ast_DeclList_free(¶ms); +--- +> ast_Decl* fd = ast_builder_Builder_actOnFunctionType(p->builder, &rtype, ast_VarDeclList_getData(¶ms), ast_VarDeclList_size(¶ms), is_variadic, ast_DefKind_Param); +> ast_VarDeclList_free(¶ms); +36423c36902 +< if (p->tok.kind == token_Kind_KW_local || p->tok.kind == token_Kind_KW_static) c2_parser_Parser_error(p, "keyword '%s' cannot be used at file scope", token_Kind_str(p->tok.kind)); +--- +> if (p->tok.kind == token_Kind_KW_local || p->tok.kind == token_Kind_KW_static) c2_parser_Parser_error(p, "keyword '%s' cannot be used at file scope", token_Kind__name[p->tok.kind]); +36546c37025 +< ast_TypeRefHolder_setBuiltin(ref, c2_parser_cTypeToBuiltinKind(c_kind), loc); +--- +> ast_TypeRefHolder_setBuiltin(ref, c2_parser_Parser_cTypeToBuiltinKind(p, c_kind), loc); +36620c37099 +< static ast_BuiltinKind c2_parser_cTypeToBuiltinKind(c2_parser_CTypeKind kind) +--- +> static ast_BuiltinKind c2_parser_Parser_cTypeToBuiltinKind(c2_parser_Parser* p, c2_parser_CTypeKind kind) +36621a37101,37112 +> if (ast_builder_Builder_getNativeLong(p->builder) == ast_BuiltinKind_Int32) { +> switch (kind) { +> case c2_parser_CTypeKind_Long: +> return ast_BuiltinKind_Int32; +> case c2_parser_CTypeKind_SignedLong: +> return ast_BuiltinKind_Int32; +> case c2_parser_CTypeKind_UnsignedLong: +> return ast_BuiltinKind_UInt32; +> default: +> break; +> } +> } +36725c37216 +< c2_parser_Parser_error(p, "TODO conditional expr"); +--- +> c2_parser_Parser_error(p, "expected expression after '?'"); +36824,36826d37314 +< res = c2_parser_Parser_parseExplicitCastExpr(p); +< break; +< case 9: +36829,36831c37317 +< case 10: +< return c2_parser_Parser_parseEnumMinMax(p, savedKind == token_Kind_KW_enum_min); +< case 11: +--- +> case 9: +36835c37321 +< case 12: +--- +> case 10: +36839c37325 +< case 13: +--- +> case 11: +36841c37327 +< case 14: +--- +> case 12: +36843c37329 +< case 15: +--- +> case 13: +36846c37332 +< case 16: +--- +> case 14: +37175,37202d37660 +< static ast_Expr* c2_parser_Parser_parseExplicitCastExpr(c2_parser_Parser* p) +< { +< src_loc_SrcLoc loc = p->tok.loc; +< c2_parser_Parser_consumeToken(p); +< c2_parser_Parser_expectAndConsume(p, token_Kind_Less); +< ast_TypeRefHolder ref; ast_TypeRefHolder_init(&ref); +< c2_parser_Parser_parseTypeSpecifier(p, &ref); +< c2_parser_Parser_expectAndConsume(p, token_Kind_Greater); +< if (ast_TypeRefHolder_isArray(&ref)) c2_parser_Parser_error(p, "array types are not allowed here"); +< c2_parser_Parser_expectAndConsume(p, token_Kind_LParen); +< ast_Expr* expr = c2_parser_Parser_parseExpr(p); +< u32 src_len = p->tok.loc + 1 - loc; +< c2_parser_Parser_expectAndConsume(p, token_Kind_RParen); +< return ast_builder_Builder_actOnExplicitCast(p->builder, loc, src_len, &ref, expr, false); +< } +< +< static ast_Expr* c2_parser_Parser_parseEnumMinMax(c2_parser_Parser* p, bool is_min) +< { +< src_loc_SrcLoc loc = p->tok.loc; +< c2_parser_Parser_consumeToken(p); +< c2_parser_Parser_expectAndConsume(p, token_Kind_LParen); +< c2_parser_Parser_expectIdentifier(p); +< ast_Expr* expr = c2_parser_Parser_parseExpr(p); +< u32 src_len = p->tok.loc + 1 - loc; +< c2_parser_Parser_expectAndConsume(p, token_Kind_RParen); +< return ast_builder_Builder_actOnBuiltinExpr(p->builder, loc, src_len, expr, is_min ? ast_BuiltinExprKind_EnumMin : ast_BuiltinExprKind_EnumMax); +< } +< +37320d37777 +< case token_Kind_KW_cast: +37322,37323d37778 +< case token_Kind_KW_enum_min: +< case token_Kind_KW_enum_max: +37622a38078,38082 +> u32 name_idx = 0; +> if (p->tok.kind == token_Kind_Identifier) { +> name_idx = p->tok.name_idx; +> c2_parser_Parser_consumeToken(p); +> } +37624c38084 +< return ast_builder_Builder_actOnBreakStmt(p->builder, loc); +--- +> return ast_builder_Builder_actOnBreakStmt(p->builder, loc, name_idx); +37630a38091,38095 +> u32 name_idx = 0; +> if (p->tok.kind == token_Kind_Identifier) { +> name_idx = p->tok.name_idx; +> c2_parser_Parser_consumeToken(p); +> } +37632c38097 +< return ast_builder_Builder_actOnContinueStmt(p->builder, loc); +--- +> return ast_builder_Builder_actOnContinueStmt(p->builder, loc, name_idx); +37661c38126,38138 +< ast_Stmt* cond = c2_parser_Parser_parseCondition(p); +--- +> c2_parser_Parser_expectAndConsume(p, token_Kind_LParen); +> ast_Stmt* decl = NULL; +> ast_Expr* cond = NULL; +> if (c2_parser_Parser_isDeclaration(p)) { +> decl = c2_parser_Parser_parseDeclStmt(p, false, false, true); +> if (p->tok.kind == token_Kind_Semicolon) { +> c2_parser_Parser_consumeToken(p); +> cond = c2_parser_Parser_parseExpr(p); +> } +> } else { +> cond = c2_parser_Parser_parseExpr(p); +> } +> c2_parser_Parser_expectAndConsume(p, token_Kind_RParen); +37668c38145 +< return ast_builder_Builder_actOnIfStmt(p->builder, loc, cond, then, else_stmt); +--- +> return ast_builder_Builder_actOnIfStmt(p->builder, loc, decl, cond, then, else_stmt); +37730c38207 +< bool is_static = (p->tok.kind == token_Kind_KW_local || p->tok.kind == token_Kind_KW_static); +--- +> bool is_static = p->tok.kind == token_Kind_KW_static; +37732,37733c38209,38210 +< if (is_static | has_tlocal) { +< if (!allowLocal) c2_parser_Parser_error(p, "keyword '%s' is not allowed here", token_Kind_str(p->tok.kind)); +--- +> if (is_static | has_tlocal || p->tok.kind == token_Kind_KW_local) { +> if (!allowLocal || p->tok.kind == token_Kind_KW_local) c2_parser_Parser_error(p, "keyword '%s' is not allowed here", token_Kind__name[p->tok.kind]); +37741a38219 +> u32 name_len = p->tok.len; +37765d38242 +< u32 name_len = p->tok.len; +37776a38254 +> c2_parser_Parser_error(p, "expected identifier after '.'"); +37808a38287,38290 +> const char* label_name = string_pool_Pool_idx2str(p->pool, name); +> if (!islower(label_name[0])) { +> c2_parser_Parser_error(p, "a label name must start with a lower case character"); +> } +37967c38449 +< ast_DeclList params; ast_DeclList_init(¶ms); +--- +> ast_VarDeclList params; ast_VarDeclList_init(¶ms); +37969c38451 +< ast_Decl* ftd = ast_builder_Builder_actOnFunctionTypeDecl(p->builder, name, loc, is_public, &rtype, (ast_VarDecl**)ast_DeclList_getDecls(¶ms), ast_DeclList_size(¶ms), is_variadic); +--- +> ast_Decl* ftd = ast_builder_Builder_actOnFunctionTypeDecl(p->builder, name, loc, is_public, &rtype, ast_VarDeclList_getData(¶ms), ast_VarDeclList_size(¶ms), is_variadic); +37971c38453 +< ast_DeclList_free(¶ms); +--- +> ast_VarDeclList_free(¶ms); +37988c38470 +< ast_StructTypeDecl* d = ast_builder_Builder_actOnStructType(p->builder, name, loc, is_public, is_struct, true, ast_DeclList_getDecls(&members), ast_DeclList_size(&members)); +--- +> ast_StructTypeDecl* d = ast_builder_Builder_actOnStructType(p->builder, name, loc, is_public, is_struct, true, ast_DeclList_getData(&members), ast_DeclList_size(&members)); +38007,38008c38489 +< while (1) { +< if (p->tok.kind == token_Kind_RBrace) break; +--- +> while (p->tok.kind != token_Kind_RBrace) { +38022c38503 +< ast_StructTypeDecl* member = ast_builder_Builder_actOnStructType(p->builder, name, loc, is_public, is_struct, false, ast_DeclList_getDecls(&sub_members), ast_DeclList_size(&sub_members)); +--- +> ast_StructTypeDecl* member = ast_builder_Builder_actOnStructType(p->builder, name, loc, is_public, is_struct, false, ast_DeclList_getData(&sub_members), ast_DeclList_size(&sub_members)); +38026a38508 +> ast_Decl* d = NULL; +38031c38513 +< ast_DeclList params; ast_DeclList_init(¶ms); +--- +> ast_VarDeclList params; ast_VarDeclList_init(¶ms); +38033,38034c38515,38516 +< ast_Decl* fd = ast_builder_Builder_actOnFunctionType(p->builder, &rtype, (ast_VarDecl**)ast_DeclList_getDecls(¶ms), ast_DeclList_size(¶ms), is_variadic, ast_DefKind_StructMember); +< ast_DeclList_free(¶ms); +--- +> ast_Decl* fd = ast_builder_Builder_actOnFunctionType(p->builder, &rtype, ast_VarDeclList_getData(¶ms), ast_VarDeclList_size(¶ms), is_variadic, ast_DefKind_StructMember); +> ast_VarDeclList_free(¶ms); +38036c38518 +< ast_TypeRefHolder_setFunction(&ref, (ast_Decl*)fd); +--- +> ast_TypeRefHolder_setFunction(&ref, fd); +38046c38528,38530 +< ast_DeclList_add(members, ast_VarDecl_asDecl(member)); +--- +> d = (ast_Decl*)member; +> ast_DeclList_add(members, d); +> c2_parser_Parser_applyAttributes(p, d, c2_parser_Parser_parseOptionalAttributes(p)); +38050a38535 +> bool multiple_decls = false; +38069c38554,38563 +< ast_DeclList_add(members, ast_VarDecl_asDecl(member)); +--- +> d = (ast_Decl*)member; +> ast_DeclList_add(members, d); +> src_loc_SrcLoc attr_loc = 0; +> if (p->tok.kind == token_Kind_At) { +> attr_loc = p->tok.loc; +> c2_parser_Parser_applyAttributes(p, d, c2_parser_Parser_parseOptionalAttributes(p)); +> } +> if (attr_loc && (multiple_decls || p->tok.kind == token_Kind_Comma)) { +> c2_parser_Parser_error(p, "attributes cannot be to applied to multiple declarations"); +> } +38070a38565 +> multiple_decls = true; +38117c38612 +< ast_DeclList assoc_values; ast_DeclList_init(&assoc_values); +--- +> ast_VarDeclList assoc_values; ast_VarDeclList_init(&assoc_values); +38162,38163c38657,38658 +< ast_EnumTypeDecl* d = ast_builder_Builder_actOnEnumType(p->builder, name, loc, is_public, is_incr, implType, (ast_EnumConstantDecl**)ast_DeclList_getDecls(&constants), ast_DeclList_size(&constants), (ast_VarDecl**)ast_DeclList_getDecls(&assoc_values), (u16)ast_DeclList_size(&assoc_values)); +< ast_DeclList_free(&assoc_values); +--- +> ast_EnumTypeDecl* d = ast_builder_Builder_actOnEnumType(p->builder, name, loc, is_public, is_incr, implType, (ast_EnumConstantDecl**)ast_DeclList_getData(&constants), ast_DeclList_size(&constants), ast_VarDeclList_getData(&assoc_values), (u16)ast_VarDeclList_size(&assoc_values)); +> ast_VarDeclList_free(&assoc_values); +38168c38663 +< static void c2_parser_Parser_parseEnumAssocAttributes(c2_parser_Parser* p, ast_DeclList* params) +--- +> static void c2_parser_Parser_parseEnumAssocAttributes(c2_parser_Parser* p, ast_VarDeclList* params) +38175c38670 +< ast_DeclList_add(params, ast_VarDecl_asDecl(decl)); +--- +> ast_VarDeclList_add(params, decl); +38184c38679 +< if (p->tok.kind == token_Kind_KW_local || p->tok.kind == token_Kind_KW_static) c2_parser_Parser_error(p, "keyword '%s' is not allowed here", token_Kind_str(p->tok.kind)); +--- +> if (p->tok.kind == token_Kind_KW_local || p->tok.kind == token_Kind_KW_static) c2_parser_Parser_error(p, "keyword '%s' is not allowed here", token_Kind__name[p->tok.kind]); +38195c38690 +< ast_DeclList params; ast_DeclList_init(¶ms); +--- +> ast_VarDeclList params; ast_VarDeclList_init(¶ms); +38197,38198c38692,38693 +< ast_Decl* fd = ast_builder_Builder_actOnFunctionType(p->builder, &rtype, (ast_VarDecl**)ast_DeclList_getDecls(¶ms), ast_DeclList_size(¶ms), is_variadic, ast_DefKind_EnumValue); +< ast_DeclList_free(¶ms); +--- +> ast_Decl* fd = ast_builder_Builder_actOnFunctionType(p->builder, &rtype, ast_VarDeclList_getData(¶ms), ast_VarDeclList_size(¶ms), is_variadic, ast_DefKind_EnumValue); +> ast_VarDeclList_free(¶ms); +38287c38782 +< ast_DeclList params; ast_DeclList_init(¶ms); +--- +> ast_VarDeclList params; ast_VarDeclList_init(¶ms); +38289,38290c38784,38785 +< d = ast_builder_Builder_actOnFunctionTypeDecl(p->builder, type_name, loc, is_public, &ref, (ast_VarDecl**)ast_DeclList_getDecls(¶ms), ast_DeclList_size(¶ms), is_variadic); +< ast_DeclList_free(¶ms); +--- +> d = ast_builder_Builder_actOnFunctionTypeDecl(p->builder, type_name, loc, is_public, &ref, ast_VarDeclList_getData(¶ms), ast_VarDeclList_size(¶ms), is_variadic); +> ast_VarDeclList_free(¶ms); +38355a38851 +> bool m32; +38408c38904 +< "fn bool match_name(const char *name, const char *pattern) {\n" +--- +> "fn bool match_name(const char* name, const char* pattern) {\n" +38429c38925 +< "fn bool match_pattern(const char *name, const char *pattern) {\n" +--- +> "fn bool match_pattern(const char* name, const char* pattern) {\n" +38431c38927 +< " for (const char *p = pattern; *p;) {\n" +--- +> " for (const char* p = pattern; *p;) {\n" +38439,38443c38935,38939 +< "fn i32 cmp_funcs(const void *a, const void *b) {\n" +< " const c2_trace_t *aa = a;\n" +< " const c2_trace_t *bb = b;\n" +< " const c2_func_t *fa = &c2_func_data[aa.callee_idx];\n" +< " const c2_func_t *fb = &c2_func_data[bb.callee_idx];\n" +--- +> "fn i32 cmp_funcs(const void* a, const void* b) {\n" +> " const c2_trace_t* aa = a;\n" +> " const c2_trace_t* bb = b;\n" +> " const c2_func_t* fa = &c2_func_data[aa.callee_idx];\n" +> " const c2_func_t* fb = &c2_func_data[bb.callee_idx];\n" +38450,38452c38946,38948 +< "fn i32 cmp_calls(const void *a, const void *b) {\n" +< " const c2_trace_t *aa = a;\n" +< " const c2_trace_t *bb = b;\n" +--- +> "fn i32 cmp_calls(const void* a, const void* b) {\n" +> " const c2_trace_t* aa = a;\n" +> " const c2_trace_t* bb = b;\n" +38456,38459c38952,38955 +< " const char *p = getenv(\"C2_TRACE\");\n" +< " const char *pattern = nil;\n" +< " const char *filename = nil;\n" +< " const char *caller = nil;\n" +--- +> " const char* p = getenv(\"C2_TRACE\");\n" +> " const char* pattern = nil;\n" +> " const char* filename = nil;\n" +> " const char* caller = nil;\n" +38488c38984 +< " u32 *counts = c2_trace_counts;\n" +--- +> " u32* counts = c2_trace_counts;\n" +38492c38988 +< " c2_trace_t *cp = &data[i];\n" +--- +> " c2_trace_t* cp = &data[i];\n" +38507c39003 +< " c2_func_t *last = nil;\n" +--- +> " c2_func_t* last = nil;\n" +38510,38511c39006,39007 +< " c2_trace_t *cp = &data[i];\n" +< " c2_func_t *func = &c2_func_data[cp.callee_idx];\n" +--- +> " c2_trace_t* cp = &data[i];\n" +> " c2_func_t* func = &c2_func_data[cp.callee_idx];\n" +38532c39028 +< static void compiler_build(string_pool_Pool* auxPool, source_mgr_SourceMgr* sm, diagnostics_Diags* diags, build_file_Info* build_info, build_target_Target* target, const compiler_Options* opts, compiler_PluginHandler* pluginHandler); +--- +> static void compiler_build(string_pool_Pool* auxPool, source_mgr_SourceMgr* sm, diagnostics_Diags* diags, build_file_Info* build_info, build_target_Target* target, const compiler_Options* opts, string_list_List* features, compiler_PluginHandler* pluginHandler); +38534c39030 +< static void compiler_Compiler_build(compiler_Compiler* c, string_pool_Pool* auxPool, source_mgr_SourceMgr* sm, diagnostics_Diags* diags, build_file_Info* build_info, build_target_Target* target, const compiler_Options* opts, compiler_PluginHandler* pluginHandler, plugin_info_Info* info); +--- +> static void compiler_Compiler_build(compiler_Compiler* c, string_pool_Pool* auxPool, source_mgr_SourceMgr* sm, diagnostics_Diags* diags, build_file_Info* build_info, build_target_Target* target, const compiler_Options* opts, string_list_List* features, compiler_PluginHandler* pluginHandler, plugin_info_Info* info); +38543c39039 +< static void compiler_Compiler_addFeature(compiler_Compiler* c, const char* str, const char* value); +--- +> static void compiler_Compiler_addFeature(compiler_Compiler* c, const char* str); +38548c39044 +< static void compiler_getNativeTarget(target_info_Info* info); +--- +> static void compiler_getNativeTarget(target_info_Info* info, bool m32); +38573c39069 +< static void compiler_build(string_pool_Pool* auxPool, source_mgr_SourceMgr* sm, diagnostics_Diags* diags, build_file_Info* build_info, build_target_Target* target, const compiler_Options* opts, compiler_PluginHandler* pluginHandler) +--- +> static void compiler_build(string_pool_Pool* auxPool, source_mgr_SourceMgr* sm, diagnostics_Diags* diags, build_file_Info* build_info, build_target_Target* target, const compiler_Options* opts, string_list_List* features, compiler_PluginHandler* pluginHandler) +38577c39073 +< compiler_Compiler_build(&c, auxPool, sm, diags, build_info, target, opts, pluginHandler, &info); +--- +> compiler_Compiler_build(&c, auxPool, sm, diags, build_info, target, opts, features, pluginHandler, &info); +38583a39080,39082 +> if (opts->print_ast_stats) { +> ast_report(); +> } +38586c39085 +< ast_deinit(c.opts->print_ast_stats); +--- +> ast_deinit(); +38607c39106 +< static void compiler_Compiler_build(compiler_Compiler* c, string_pool_Pool* auxPool, source_mgr_SourceMgr* sm, diagnostics_Diags* diags, build_file_Info* build_info, build_target_Target* target, const compiler_Options* opts, compiler_PluginHandler* pluginHandler, plugin_info_Info* info) +--- +> static void compiler_Compiler_build(compiler_Compiler* c, string_pool_Pool* auxPool, source_mgr_SourceMgr* sm, diagnostics_Diags* diags, build_file_Info* build_info, build_target_Target* target, const compiler_Options* opts, string_list_List* features, compiler_PluginHandler* pluginHandler, plugin_info_Info* info) +38609c39108 +< memset(c, 0, 992); +--- +> memset(c, 0, 896); +38622c39121 +< compiler_Compiler_addFeature(c, "BOOTSTRAP", "1"); +--- +> compiler_Compiler_addFeature(c, "BOOTSTRAP"); +38632,38633c39131 +< c->context = ast_context_create(16 * 1024); +< c->astPool = string_pool_create(128 * 1024, 4096); +--- +> c->astPool = string_pool_create(128 * 1024, 8192); +38640,38641d39137 +< c->attr_handler = attr_handler_create(diags, build_target_Target_getWarnings(target)); +< c->builder = ast_builder_create(c->context, diags, c->astPool, c->auxPool, c2_idx, c->main_idx, c->attr_handler); +38670c39166 +< compiler_getNativeTarget(&c->targetInfo); +--- +> compiler_getNativeTarget(&c->targetInfo, opts->m32); +38678c39174 +< compiler_getNativeTarget(&c->targetInfo); +--- +> compiler_getNativeTarget(&c->targetInfo, opts->m32); +38683,38690c39179,39190 +< if (c->targetInfo.intWidth == 64) { +< compiler_Compiler_addFeature(c, "ARCH_64BIT", "1"); +< } else { +< compiler_Compiler_addFeature(c, "ARCH_32BIT", "1"); +< } +< if (opts->asan) compiler_Compiler_addFeature(c, "__ASAN__", "1"); +< if (opts->msan) compiler_Compiler_addFeature(c, "__MSAN__", "1"); +< if (opts->ubsan) compiler_Compiler_addFeature(c, "__UBSAN__", "1"); +--- +> compiler_Compiler_addFeature(c, c->targetInfo.ptrWidth == 32 ? "ARCH_32BIT" : "ARCH_64BIT"); +> compiler_Compiler_addFeature(c, c->targetInfo.longWidth == 32 ? "LONG_32BIT" : "LONG_64BIT"); +> if (opts->asan) compiler_Compiler_addFeature(c, "__ASAN__"); +> if (opts->msan) compiler_Compiler_addFeature(c, "__MSAN__"); +> if (opts->ubsan) compiler_Compiler_addFeature(c, "__UBSAN__"); +> for (u32 i = 0; i < string_list_List_length(features); i++) { +> compiler_Compiler_addFeature(c, string_list_List_get(features, i)); +> } +> c->context = ast_context_create(16 * 1024, c->targetInfo.ptrWidth / 8, c->targetInfo.longWidth / 8); +> ast_initialize(c->context, c->astPool, color_useColor()); +> c->attr_handler = attr_handler_create(diags, c->astPool, build_target_Target_getWarnings(target)); +> c->builder = ast_builder_create(c->context, diags, c->astPool, c->auxPool, c2_idx, c->main_idx, c->attr_handler); +38692d39191 +< ast_initialize(c->context, c->astPool, c->targetInfo.intWidth / 8, color_useColor()); +38822c39321 +< module_analyser_Analyser_check(c->analyser, m); +--- +> module_analyser_Analyser_checkModule(c->analyser, m); +38829c39328 +< module_analyser_Analyser_check(c->analyser, m); +--- +> module_analyser_Analyser_checkModule(c->analyser, m); +38841c39340 +< static void compiler_Compiler_addFeature(compiler_Compiler* c, const char* str, const char* value) +--- +> static void compiler_Compiler_addFeature(compiler_Compiler* c, const char* str) +38859c39358 +< compiler_Compiler_addFeature(c, tmp, "1"); +--- +> compiler_Compiler_addFeature(c, tmp); +38892c39391 +< c_generator_generate(c->astPool, c->auxPool, target_name, build_target_Target_getKind(c->target), output_dir, c->diags, c->sm, c->build_info, &c->targetInfo, &c->components, c->mainFunc, &asm_files, build_target_Target_hasAsserts(c->target), build_target_Target_getFastBuild(c->target) | c->opts->fast_build, c->opts->asan, c->opts->msan, c->opts->ubsan, c->opts->test_mode, c->opts->trace_calls); +--- +> c_generator_generate(c->astPool, c->auxPool, target_name, build_target_Target_getKind(c->target), output_dir, c->diags, c->sm, c->build_info, &c->targetInfo, &c->components, c->mainFunc, &asm_files, build_target_Target_hasAsserts(c->target), build_target_Target_getFastBuild(c->target) | c->opts->fast_build, c->opts->asan, c->opts->msan, c->opts->ubsan, c->opts->m32, c->opts->test_mode, c->opts->trace_calls); +38911c39410 +< static void compiler_getNativeTarget(target_info_Info* info) +--- +> static void compiler_getNativeTarget(target_info_Info* info, bool m32) +38945c39444 +< info->arch = target_info_str2arch(un.machine); +--- +> info->arch = target_info_str2arch(un.machine, m32); +38961c39460 +< info->arch = target_info_str2arch(arch_str); +--- +> info->arch = target_info_str2arch(arch_str, false); +39323a39823 +> const char* mod_name = string_pool_Pool_idx2str(c->astPool, name_idx); +39326c39826 +< diagnostics_Diags_error(c->diags, ast_Decl_getLoc(d), "module '%s' is private to component %s", ast_idx2name(name_idx), component_Component_getName(comp)); +--- +> diagnostics_Diags_error(c->diags, ast_Decl_getLoc(d), "module '%s' is private to component %s", mod_name, component_Component_getName(comp)); +39328c39828 +< diagnostics_Diags_error(c->diags, ast_Decl_getLoc(d), "module '%s' is defined in component %s that is not a dependency of component %s", ast_idx2name(name_idx), component_Component_getName(comp), component_Component_getName(c->current)); +--- +> diagnostics_Diags_error(c->diags, ast_Decl_getLoc(d), "module '%s' is defined in component %s that is not a dependency of component %s", mod_name, component_Component_getName(comp), component_Component_getName(c->current)); +39331c39831 +< diagnostics_Diags_error(c->diags, ast_Decl_getLoc(d), "unknown module: '%s'", ast_idx2name(name_idx)); +--- +> diagnostics_Diags_error(c->diags, ast_Decl_getLoc(d), "unknown module: '%s'", mod_name); +39417c39917 +< unused_checker_check(c->diags, build_target_Target_getWarnings(c->target), m); +--- +> unused_checker_check(c->diags, c->astPool, build_target_Target_getWarnings(c->target), m); +39431a39932 +> bool quiet_mode; +39440a39942 +> string_list_List features; +39459a39962 +> char build_filename[512]; +39467c39970,39981 +< static const char c2c_main_Recipe_help[979] = "---- recipe.txt ----\n\n" +--- +> static const char c2c_main_GenMain[78] = "module %s_main;\n\n" +> "public fn i32 main(i32 argc, char** argv) {\n" +> " return 0;\n" +> "}\n"; +> static const char c2c_main_GenRecipe[158] = "plugin deps_generator [all-targets files private]\n" +> "plugin refs_generator [all-targets]\n\n" +> "executable %s\n" +> " $warnings no-unused\n" +> " $backend c\n\n" +> " main.c2\n" +> "end\n"; +> static const char c2c_main_Recipe_help[975] = "---- recipe.txt ----\n\n" +39481c39995 +< " \n" +--- +> " \n" +39483c39997 +< " \n" +--- +> " \n" +39487,39488c40001,40002 +< " \n" +< " \n" +--- +> " \n" +> " \n" +39506c40020 +< static const char c2c_main_Usage_help[1831] = "Usage: c2c []\n" +--- +> static const char c2c_main_Usage_help[2009] = "Usage: c2c []\n" +39512a40027 +> " -Dfeature[=value] define global feature with optional value\n" +39517a40033 +> " -m32 generate 32-bit code on selected targets\n" +39541a40058 +> " -q --quiet prevent compiler logging messages\n" +39544c40061 +< " --version print version\n"; +--- +> " --version print version;\n"; +39576c40093 +< memset(opts, 0, 88); +--- +> memset(opts, 0, 72); +39578a40096 +> string_list_List_init(&opts->features, pool); +39584a40103 +> string_list_List_free(&opts->features); +39603,39606c40122 +< string_buffer_Buf_print(buf, "module %s_main;\n\n" +< "public fn i32 main(i32 argc, char** argv) {\n\n" +< " return 0;\n" +< "}\n", name); +--- +> string_buffer_Buf_print(buf, c2c_main_GenMain, name); +39609,39615c40125 +< string_buffer_Buf_print(buf, "plugin deps_generator [all-targets files private]\n" +< "plugin refs_generator [all-targets]\n\n" +< "executable %s\n" +< " $warnings no-unused\n" +< " $backend c\n\n" +< " main.c2\n" +< "end\n", name); +--- +> string_buffer_Buf_print(buf, c2c_main_GenRecipe, name); +39673c40183 +< switch (c2_strswitch(arg + 2, "\002I2\tbootstrap\005check\006create\004fast\bno-build\004help\vhelp-recipe\tnoplugins\bshowlibs\vshowplugins\006target\atargets\004test\vtrace-calls\004asan\004msan\005ubsan\aversion")) { +--- +> switch (c2_strswitch(arg + 2, "\002I2\tbootstrap\005check\006create\004fast\bno-build\004help\vhelp-recipe\tnoplugins\005quiet\bshowlibs\vshowplugins\006target\atargets\004test\vtrace-calls\004asan\004msan\005ubsan\aversion")) { +39702c40212,40215 +< case 11: // "showlibs" +--- +> case 11: // "quiet" +> opts->quiet_mode = true; +> break; +> case 12: // "showlibs" +39705c40218 +< case 12: // "showplugins" +--- +> case 13: // "showplugins" +39708c40221 +< case 13: // "target" +--- +> case 14: // "target" +39711c40224 +< case 14: // "targets" +--- +> case 15: // "targets" +39714c40227 +< case 15: // "test" +--- +> case 16: // "test" +39717c40230 +< case 16: // "trace-calls" +--- +> case 17: // "trace-calls" +39720c40233 +< case 17: // "asan" +--- +> case 18: // "asan" +39723c40236 +< case 18: // "msan" +--- +> case 19: // "msan" +39726c40239 +< case 19: // "ubsan" +--- +> case 20: // "ubsan" +39729c40242 +< case 20: // "version" +--- +> case 21: // "version" +39746,39747c40259,40263 +< if (strlen(arg) != 2) { +< switch (c2_strswitch(arg + 1, "\004help\002lm")) { +--- +> const char* argarg = NULL; +> if (memchr("Ddbo", arg[1], 4)) { +> argarg = arg[2] ? &arg[2] : c2c_main_ArgumentParser_getOptionArgument(ap, arg); +> } else if (strlen(arg) != 2) { +> switch (c2_strswitch(arg + 1, "\004help\002lm\003m32\003m64")) { +39753a40270,40275 +> case 4: // "m32" +> comp_opts->m32 = true; +> continue; +> case 5: // "m64" +> comp_opts->m32 = false; +> continue; +39763a40286,40288 +> case 'D': +> string_list_List_addStr(&opts->features, argarg); +> break; +39778c40303 +< opts->build_file = c2c_main_ArgumentParser_getOptionArgument(ap, arg); +--- +> opts->build_file = argarg; +39781c40306 +< opts->other_dir = c2c_main_ArgumentParser_getOptionArgument(ap, arg); +--- +> opts->other_dir = argarg; +39794c40319,40322 +< opts->output_name = c2c_main_ArgumentParser_getOptionArgument(ap, arg); +--- +> opts->output_name = argarg; +> break; +> case 'q': +> opts->quiet_mode = true; +39859c40387 +< memset(c, 0, 1264); +--- +> memset(c, 0, 1696); +39873a40402,40405 +> console_setQuiet(c->opts.quiet_mode); +> const char notFound[163] = "c2c: error: cannot find project root directory\n" +> " c2c requires a %s file in the project root,\n" +> " Use argument -h for c2c usage and a list of available options"; +39875c40407,40415 +< if (chdir(c->opts.other_dir)) { +--- +> if (string_list_List_length(&c->opts.files)) { +> console_error("c2c: The -d option cannot be combined with "); +> exit(stdlib_EXIT_FAILURE); +> } +> u32 err = utils_changeToProjectDir(&c->path_info, c->opts.other_dir); +> switch (err) { +> case 0: +> break; +> case 2: +39877a40418,40422 +> break; +> case 3: +> console_error(notFound, constants_recipe_name); +> exit(stdlib_EXIT_FAILURE); +> break; +39896,39899c40441,40442 +< if (!utils_findProjectDir(&c->path_info)) { +< console_error("c2c: error: cannot find project root directory\n" +< " c2c requires a %s file in the project root,\n" +< " Use argument -h for c2c usage and a list of available options", constants_recipe_name); +--- +> if (!c->opts.other_dir && !utils_findProjectDir(&c->path_info)) { +> console_error(notFound, constants_recipe_name); +39905a40449 +> bool auto_found_buildfile = false; +39907a40452 +> auto_found_buildfile = true; +39909c40454,40455 +< c->plugins = plugin_mgr_create(c->auxPool, c->opts.print_timing, c->opts.log_verbose, c->opts.no_plugins); +--- +> c->plugins = plugin_mgr_create(c->auxPool, console_getConfig(), c->opts.no_plugins); +> bool have_plugin_dir = false; +39911,39912c40457,40463 +< console_log("using build-file %s", c->opts.build_file); +< c->build_info = build_file_parser_parse(c->sm, c->auxPool, c->opts.build_file); +--- +> if (auto_found_buildfile) { +> strcpy(c->build_filename, c->opts.build_file); +> } else { +> snprintf(c->build_filename, 512, "%s%s", c->path_info.orig2root, c->opts.build_file); +> } +> console_log("using build-file %s", c->build_filename); +> c->build_info = build_file_parser_parse(c->sm, c->auxPool, c->build_filename); +39915a40467 +> have_plugin_dir = true; +39930c40482,40483 +< } else { +--- +> } +> if (!have_plugin_dir) { +39932a40486 +> else console_warn("environment variable C2_PLUGINDIR not set!"); +40011c40565 +< compiler_build(c->auxPool, c->sm, c->diags, c->build_info, target, &c->comp_opts, &c->pluginHandler); +--- +> compiler_build(c->auxPool, c->sm, c->diags, c->build_info, target, &c->comp_opts, &c->opts.features, &c->pluginHandler); +40058c40612 +< console_init(); +--- +> console_init(NULL); diff --git a/bootstrap/globals.c b/bootstrap/globals.c index 05ae32c57..49b101c2e 100644 --- a/bootstrap/globals.c +++ b/bootstrap/globals.c @@ -1128,7 +1128,14 @@ int main(int argc, char *argv[]) { #endif printf("\n"); #ifdef MAP_FAILED - printf("const usize MAP_FAILED = (usize)(%lld);\n", (long long)MAP_FAILED); + if (sizeof(void*) == sizeof(long long)) { + printf("const usize MAP_FAILED = (usize)(%lld);\n", (long long)MAP_FAILED); + } else + if (sizeof(void*) == sizeof(long)) { + printf("const usize MAP_FAILED = (usize)(%ld);\n", (long)MAP_FAILED); + } else { + printf("const usize MAP_FAILED = (usize)(%d);\n", (int)MAP_FAILED); + } #endif printf("\n"); preprocess_header("sys/mman.h"); @@ -1139,6 +1146,8 @@ int main(int argc, char *argv[]) { } printf("}\n"); printf("// libc/sys_stat.c2i\n{\n"); { + printf("const u32 STAT_SIZE = %zu;\n", sizeof(struct stat)); + printf("\n"); preprocess_header("sys/stat.h"); } printf("}\n"); @@ -1161,8 +1170,6 @@ int main(int argc, char *argv[]) { #ifdef STDERR_FILENO printf("const int STDERR_FILENO = %d;\n", STDERR_FILENO); #endif - printf("\n"); - printf("const u32 STAT_SIZE = %zu;\n", sizeof(struct stat)); printf("\n"); printf("/* access flags. */\n"); #ifdef R_OK diff --git a/common/ast_builder.c2 b/common/ast_builder.c2 index 29af336a8..b54c61981 100644 --- a/common/ast_builder.c2 +++ b/common/ast_builder.c2 @@ -42,6 +42,7 @@ public type Builder struct @(opaque) { bool is_interface; bool is_private; BuiltinKind native_kind; + BuiltinKind native_long; Attr[8] attrs; u32 num_attrs; @@ -64,7 +65,8 @@ public fn Builder* create(Context* context, b.auxPool = auxPool; b.c2_name = c2_name; b.main_name = main_name; - b.native_kind = context.getWordSize() == 8 ? UInt64 : UInt32; + b.native_kind = context.getPointerSize() == 8 ? UInt64 : UInt32; + b.native_long = context.getLongSize() == 8 ? Int64 : Int32; b.attr_handler = attr_handler_; return b; @@ -101,6 +103,10 @@ public fn BuiltinKind Builder.getNativeKind(Builder* b) { return b.native_kind; } +public fn BuiltinKind Builder.getNativeLong(Builder* b) { + return b.native_long; +} + public fn void Builder.actOnModule(Builder* b, u32 mod_name, SrcLoc mod_loc, diff --git a/common/target_info.c2 b/common/target_info.c2 index 9240ba307..a29e10ed2 100644 --- a/common/target_info.c2 +++ b/common/target_info.c2 @@ -18,15 +18,15 @@ module target_info; import stdio local; import string local; -public type Arch enum u8 (const char* const name) { - Unknown : { "unknown" }, - I686 : { "i686" }, - Arm : { "arm" }, - X86_64 : { "x86_64" }, - Amd64 : { "amd64" }, - Arm64 : { "arm64" }, - Riscv_32 : { "riscv32" }, - Riscv_64 : { "riscv64" }, +public type Arch enum u8 (const char* const name, Arch m32_version) { + Unknown : { "unknown", Unknown }, + I686 : { "i686", I686 }, + Arm : { "arm", Arm }, + X86_64 : { "x86_64", I686 }, + Amd64 : { "amd64", I686 }, + Arm64 : { "arm64", Arm }, + Riscv_32 : { "riscv32", Riscv_32 }, + Riscv_64 : { "riscv64", Riscv_32 }, } public type System enum u8 (const char* const name) { @@ -60,9 +60,9 @@ public fn System str2sys(const char* name) { return Unknown; } -public fn Arch str2arch(const char* name) { - for (Arch i = Arch.min; i <= Arch.max; i++) { - if (strcasecmp(i.name, name) == 0) return i; +public fn Arch str2arch(const char* name, bool m32 = false) { + for (Arch a = Arch.min; a <= Arch.max; a++) { + if (strcasecmp(a.name, name) == 0) return m32 ? a.m32_version : a; } return Unknown; } diff --git a/compiler/compiler.c2 b/compiler/compiler.c2 index ddcad1929..391cef463 100644 --- a/compiler/compiler.c2 +++ b/compiler/compiler.c2 @@ -79,6 +79,7 @@ public type Options struct { bool asan; bool msan; bool ubsan; + bool m32; const char* libdir; // no ownership, from environment variable C2_LIBDIR const char* target_triple; } @@ -255,7 +256,7 @@ fn void Compiler.build(Compiler* c, // parse into multiple, add each to string-pool string_utils.split_paths(c.opts.libdir, c, Compiler.addLibPath); } - getNativeTarget(&c.targetInfo); + getNativeTarget(&c.targetInfo, opts.m32); } if (target_str) { if (!fromString(&c.targetInfo, target_str)) { @@ -263,7 +264,7 @@ fn void Compiler.build(Compiler* c, stdlib.exit(-1); } } else { - getNativeTarget(&c.targetInfo); + getNativeTarget(&c.targetInfo, opts.m32); } console.debug("triple: %s", c.targetInfo.str()); @@ -285,7 +286,7 @@ fn void Compiler.build(Compiler* c, // TODO: reorganize these objects: // ast.AstContext should the global object - c.context = ast_context.create(16*1024, c.targetInfo.ptrWidth / 8); + c.context = ast_context.create(16*1024, c.targetInfo.ptrWidth / 8, c.targetInfo.longWidth / 8); ast.initialize(c.context, c.astPool, color.useColor()); c.attr_handler = attr_handler.create(diags, c.astPool, target.getWarnings()); diff --git a/compiler/compiler_generate.c2 b/compiler/compiler_generate.c2 index a144a45ae..92d4b8056 100644 --- a/compiler/compiler_generate.c2 +++ b/compiler/compiler_generate.c2 @@ -83,7 +83,7 @@ fn void Compiler.generate(Compiler* c, const char* target_name, const char* outp &asm_files, c.target.hasAsserts(), c.target.getFastBuild() | c.opts.fast_build, - c.opts.asan, c.opts.msan, c.opts.ubsan, + c.opts.asan, c.opts.msan, c.opts.ubsan, c.opts.m32, c.opts.test_mode, c.opts.trace_calls); asm_files.free(); u64 gen4 = utils.now(); diff --git a/compiler/compiler_target.c2 b/compiler/compiler_target.c2 index 25c4c1c30..fdc5f2269 100644 --- a/compiler/compiler_target.c2 +++ b/compiler/compiler_target.c2 @@ -24,7 +24,7 @@ import stdio local; import stdlib local; import string; -fn void getNativeTarget(Info* info) { +fn void getNativeTarget(Info* info, bool m32 = false) { sys_utsname.Name un; if (sys_utsname.uname(&un) != 0) { console.error("error getting system info: %s", string.strerror(errno)); @@ -59,7 +59,7 @@ fn void getNativeTarget(Info* info) { break; } - info.arch = str2arch(un.machine); + info.arch = str2arch(un.machine, m32); if (info.arch == Unknown) { console.error("unsupported arch: '%s'", un.machine); exit(EXIT_FAILURE); diff --git a/compiler/main.c2 b/compiler/main.c2 index 65f8126ae..87d693d0a 100644 --- a/compiler/main.c2 +++ b/compiler/main.c2 @@ -202,6 +202,7 @@ Options: -I use IR backend and print generated IR -lm link the math module -m print modules + -m32 generate 32-bit code on selected targets -o [file] force the output name for a single target -r print reports -s print symbols @@ -359,6 +360,12 @@ fn void parse_arguments(ArgumentParser* ap, compiler.Options* comp_opts, Options case "lm": opts.use_math_library = true; continue; + case "m32": + comp_opts.m32 = true; + continue; + case "m64": + comp_opts.m32 = false; + continue; } ap.unknownOption(arg); } diff --git a/generator/c/c_generator.c2 b/generator/c/c_generator.c2 index 1efa9c07c..a7ded57c1 100644 --- a/generator/c/c_generator.c2 +++ b/generator/c/c_generator.c2 @@ -79,6 +79,7 @@ type Generator struct { bool asan; bool msan; bool ubsan; + bool m32; bool trace_calls; bool no_trace; //to disable tracing on c2_trace module u32 indent; @@ -1283,7 +1284,7 @@ public fn void generate(string_pool.Pool* astPool, Decl* mainFunc, string_list.List* asm_files, bool enable_asserts, - bool fast_build, bool asan, bool msan, bool ubsan, + bool fast_build, bool asan, bool msan, bool ubsan, bool m32, bool test_mode, bool trace_calls) { char[file_utils.Max_path] dir; @@ -1300,6 +1301,7 @@ public fn void generate(string_pool.Pool* astPool, gen.asan = asan; gen.msan = msan; gen.ubsan = ubsan; + gen.m32 = m32; gen.trace_calls = trace_calls; gen.targetInfo = targetInfo; gen.cgen_dir = dir; diff --git a/generator/c/c_generator_special.c2 b/generator/c/c_generator_special.c2 index 795b51717..9e9ac1e32 100644 --- a/generator/c/c_generator_special.c2 +++ b/generator/c/c_generator_special.c2 @@ -88,6 +88,10 @@ fn void Generator.createMakefile(Generator* gen, out.add("CFLAGS+=-fsanitize=undefined -D__UBSAN__ -O0\n"); out.add("LDFLAGS+=-fsanitize=undefined\n"); } + if (gen.m32) { + out.add("CFLAGS+=-m32\n"); + out.add("LDFLAGS+=-m32\n"); + } char[Max_path] target_name; diff --git a/generator/ir/field_struct_layouter.c2 b/generator/ir/field_struct_layouter.c2 index 1cb727b55..724e9cb63 100644 --- a/generator/ir/field_struct_layouter.c2 +++ b/generator/ir/field_struct_layouter.c2 @@ -27,7 +27,7 @@ type FieldInit struct { const ast.FieldInitField* info; ast.Expr* expr; } -static_assert(16, sizeof(FieldInit)); +static_assert(sizeof(void*) == 4 ? 8 : 16, sizeof(FieldInit)); type FieldStructLayouter struct { Generator* gen; diff --git a/ir/function_info.c2 b/ir/function_info.c2 index 94c71b2cd..7d3c549e8 100644 --- a/ir/function_info.c2 +++ b/ir/function_info.c2 @@ -29,7 +29,7 @@ public type FunctionInfo struct { u8[1 + constants.MaxCallArgs/2] args; // stores 2 ir.Types per u8, first low, then high bits u32 id; } -static_assert(88, sizeof(FunctionInfo)); +static_assert(sizeof(void*) == 4 ? 68 : 88, sizeof(FunctionInfo)); public fn FunctionInfo* FunctionInfo.create(u32 id, u32 num_blks, u32 num_instr, u32 num_refs) { FunctionInfo* fi = stdlib.malloc(sizeof(FunctionInfo)); diff --git a/ir/inserter.c2 b/ir/inserter.c2 index 817e6369b..31457eb76 100644 --- a/ir/inserter.c2 +++ b/ir/inserter.c2 @@ -51,7 +51,7 @@ public type Inserter struct { u32 split_count; u32 split_cap; } -static_assert(72, sizeof(Inserter)); +static_assert(sizeof(void*) == 4 ? 56 : 72, sizeof(Inserter)); public fn void Inserter.create(Inserter* ins) { string.memset(ins, 0, sizeof(Inserter)); diff --git a/ir/interference_graph.c2 b/ir/interference_graph.c2 index e239115e1..07a848546 100644 --- a/ir/interference_graph.c2 +++ b/ir/interference_graph.c2 @@ -63,7 +63,7 @@ public type InterferenceGraph struct @(opaque) { u32 queue_count; u32 queue_head; } -static_assert(224, sizeof(InterferenceGraph)); +static_assert(sizeof(void*) == 4 ? 208 : 224, sizeof(InterferenceGraph)); // Note: map size must be a multiple of largest arena size (so 256) public fn InterferenceGraph* create(u32 max_elems, u16 num_variables, u16 num_regs) { diff --git a/ir/live_map.c2 b/ir/live_map.c2 index 2982becda..803fa88e3 100644 --- a/ir/live_map.c2 +++ b/ir/live_map.c2 @@ -53,7 +53,7 @@ public type Map struct @(opaque) { u32 max_elems; // only used for dump Arena[NumArenas] arenas; } -static_assert(168, sizeof(Map)); +static_assert(sizeof(void*) == 4 ? 160 : 168, sizeof(Map)); // Note: map size must be a multiple of largest arena size (so 256) public fn Map* create(u32 max_elems, u16 num_variables) { diff --git a/ir/print.c2 b/ir/print.c2 index 6655d6984..6311f6ceb 100644 --- a/ir/print.c2 +++ b/ir/print.c2 @@ -445,7 +445,7 @@ fn void PrintHelper.printInstr(PrintHelper* ph, const Instr* blk_instrs, u32 blk out.color(color.Normal); out.add(" [ "); const PhiClause* clauses = ph.cur_info.phis.get((u32)i.args[0].value); - for (u32 j=0; j