Skip to content

Commit fbdd698

Browse files
author
Pascal Beyer
committed
Fix two small bugs and update the Readme for release.
1 parent 02ea6ec commit fbdd698

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ local functions, etc, but all of these should be considered in the "design"-stag
2828

2929
See the [release page](https://github.com/PascalBeyer/Headerless-C-Compiler/releases) for pre-build binaries. To compile from source invoke the `build_msvc.bat` with `cl.exe`,
3030
`link.exe` and `ucrt.lib` in your path (for example, from an [x64 Native Tools Command Prompt](https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170&viewFallbackFrom=vs-2019)).
31+
For a release build of the compiler you can use `build_msvc.bat release`.
3132

3233
To use standard library or Windows library functions it is necessary to install a version of the [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/).
3334

@@ -191,9 +192,7 @@ by re-iterating the syntax tree of all declarations and functions that made it i
191192

192193
## Current State and Next Steps
193194

194-
At this point, most C-code that compiles using MSVC also compiles using `hlc`. Notable exceptions include code, which uses
195-
[`__declspec(allocate("<section>"))`](https://learn.microsoft.com/en-us/cpp/cpp/allocate?view=msvc-170)
196-
or [structured exception handling](https://learn.microsoft.com/en-us/windows/win32/debug/structured-exception-handling).
195+
At this point, most C-code that compiles using MSVC also compiles using `hlc`.
197196

198197
Code-wise, most of the C-components (`preprocess.c`, `parse.c`, `emit_x64.c`) are hardened through test suites and fuzz-testing.
199198
Some larger refactors are on the "eventually"-list, like separating out the concept of `tokens` and `preprocessor` tokens.

build_msvc.bat

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ IF NOT EXIST build mkdir build
88
set warning_options= -Wall -wd4201 -wd4820 -wd4711 -wd4200 -wd4204 -wd4214 -wd4324 -wd5045 -wd4061 -wd4221 -wd4366
99
:: ********************************************************************************************************
1010

11-
set compiler_flags= -Od -nologo -fp:fast -GR- -EHa- -Zo -Oi -D_Debug %warning_options% -FC -Z7 -GS- -Gs9999999 /diagnostics:column /TC
11+
set optimization= -Od
12+
13+
if "%1" == "release" set optimization= -O2
14+
15+
set compiler_flags= %optimization% -nologo -fp:fast -GR- -EHa- -Zo -Oi -D_Debug %warning_options% -FC -Z7 -GS- -Gs9999999 /diagnostics:column /TC
1216

1317
set linker_flags= -HEAP:0,0 -STACK:0x100000,0x100000 -incremental:no -opt:ref Advapi32.lib kernel32.lib ucrt.lib /NODEFAULTLIB /ENTRY:_start /SUBSYSTEM:console /NOLOGO /DEBUG
1418

examples/tinycc.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cd tinycc\win32 || exit /b 1
55
git clean -xdf
66

77
set TCC_C=..\tcc.c
8-
build-tcc.bat -c hlc.exe -t 64 || exit /b 1
8+
call build-tcc.bat -c hlc.exe -t 64 || exit /b 1
99

1010
cd ..\..
1111

src/emit_x64.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ func struct emit_location *emit_load_into_specific_gpr(struct context *context,
14401440
func struct emit_location *emit_load_float_into_specific_register(struct context *context, struct emit_location *loc, enum register_encoding reg){
14411441

14421442

1443-
if(loc->state == EMIT_LOCATION_loaded && loc->loaded_register == reg) return loc;
1443+
if(loc->state == EMIT_LOCATION_loaded && loc->loaded_register == reg && loc->register_kind == REGISTER_KIND_xmm) return loc;
14441444

14451445
struct prefixes sse_prefix;
14461446
if(loc->size == 32){
@@ -1452,6 +1452,11 @@ func struct emit_location *emit_load_float_into_specific_register(struct context
14521452
allocate_specific_register(context, REGISTER_KIND_xmm, reg);
14531453
struct emit_location *ret = emit_location_loaded(context, REGISTER_KIND_xmm, reg, loc->size);
14541454

1455+
// @cleanup: This is stupid, we should rework the back-end to keep track of the register_kind again.
1456+
if(loc->state == EMIT_LOCATION_loaded && loc->register_kind != REGISTER_KIND_xmm){
1457+
spill_register(context, REGISTER_KIND_gpr, loc->loaded_register);
1458+
}
1459+
14551460
switch(loc->state){
14561461
case EMIT_LOCATION_loaded:{
14571462
assert(loc->register_kind == REGISTER_KIND_xmm);

src/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4866,7 +4866,9 @@ globals.typedef_##postfix = (struct ast_type){
48664866

48674867
// Ensure that all thread wrote in `thread_infos[thread_index].context`.
48684868
for(u32 thread_index = 1; thread_index < thread_count; thread_index++){
4869-
while(atomic_load(struct context *, thread_infos[thread_index].context) == null){};
4869+
while(atomic_load(struct context *, thread_infos[thread_index].context) == null){
4870+
_mm_pause();
4871+
};
48704872
}
48714873

48724874
assert(globals.work_queue_tokenize_files.work_entries_in_flight == 0);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
double function_returning_double(double number){
3+
double a;
4+
return a = number;
5+
}
6+
7+
8+
int main(){
9+
return function_returning_double(0);
10+
}

0 commit comments

Comments
 (0)