Skip to content

Commit

Permalink
remove isDarwinStdio hack
Browse files Browse the repository at this point in the history
generator:
* remove `Generator` fields: `isDarwinStdio`, `stdioName`, `stdinName`,
  `stdoutName`, `stderrName`
* rename `vxprintf` arguments for consistency
  • Loading branch information
chqrlie committed Jan 20, 2025
1 parent 2645aca commit afbc2d5
Showing 1 changed file with 3 additions and 37 deletions.
40 changes: 3 additions & 37 deletions generator/c_generator.c2
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ type Generator struct {

// to filter exceptions
u32 stdargName;
bool isDarwinStdio;
u32 stdioName;
u32 stdinName;
u32 stdoutName;
u32 stderrName;

Module* mod;

Expand Down Expand Up @@ -527,29 +522,6 @@ fn bool Generator.emitGlobalVarDecl(Generator* gen, string_buffer.Buf* out, Decl

QualType qt = d.getType();

if (gen.isDarwinStdio) {
// Darwin workaround, since it defines stdin/out/err as #define stdin __stdinp, etc
u32 name = d.getNameIdx();
if (name == gen.stdinName) {
out.add("#define stdin __stdinp\n");
out.add("extern FILE* __stdinp;\n");
out.newline();
return true;
}
if (name == gen.stdoutName) {
out.add("#define stdout __stdoutp\n");
out.add("extern FILE* __stdoutp;\n");
out.newline();
return true;
}
if (name == gen.stderrName) {
out.add("#define stderr __stderrp\n");
out.add("extern FILE* __stderrp;\n");
out.newline();
return true;
}
}

// emit 'simple'-constants as a defines
if (emitAsDefine(vd)) {
out.add("#define ");
Expand Down Expand Up @@ -1109,8 +1081,6 @@ fn void Generator.on_module(void* arg, Module* m) {
out.print("\n// --- module %s ---\n", gen.mod_name);
}

gen.isDarwinStdio = (m.getNameIdx() == gen.stdioName) && gen.targetInfo.sys == target_info.System.Darwin;

// Note: special case for stdarg.h va_list
if (m.getNameIdx() == gen.stdargName) {
if (gen.fast_build) out = gen.header;
Expand All @@ -1119,9 +1089,9 @@ fn void Generator.on_module(void* arg, Module* m) {
out.add("#define va_start __builtin_va_start\n");
out.add("#define va_end __builtin_va_end\n");
out.newline();
out.add("int32_t vdprintf(int32_t __fd, const char* __fmt, va_list __arg);\n");
out.add("int32_t vsprintf(char* str, const char* format, va_list __ap);\n");
out.add("int32_t vsnprintf(char* str, uint64_t size, const char* format, va_list __ap);\n");
out.add("int32_t vdprintf(int32_t fd, const char* format, va_list ap);\n");
out.add("int32_t vsprintf(char* str, const char* format, va_list ap);\n");
out.add("int32_t vsnprintf(char* str, uint64_t size, const char* format, va_list ap);\n");
out.newline();

// set all decls to generated
Expand Down Expand Up @@ -1191,10 +1161,6 @@ fn void Generator.init(Generator* gen,
gen.decls.init(16);

gen.stdargName = astPool.addStr("stdarg", true);
gen.stdioName = astPool.addStr("stdio", true);
gen.stdinName = astPool.addStr("stdin", true);
gen.stdoutName = astPool.addStr("stdout", true);
gen.stderrName = astPool.addStr("stderr", true);
}

fn void Generator.free(Generator* gen) {
Expand Down

0 comments on commit afbc2d5

Please sign in to comment.