Skip to content

Commit

Permalink
[cpp] debug/release is now vaguely respected. release does not enable…
Browse files Browse the repository at this point in the history
… any optimisations, but it does prevent debug info from being added. note that debug info is basically 0 right now anyway.
  • Loading branch information
harrand committed May 21, 2024
1 parent 3195c30 commit 64d3f6c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 114 deletions.
2 changes: 1 addition & 1 deletion cpp/src/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace build
{
*semal_timers += timer::elapsed_millis();
}
code::output metacode = code::generate(metaprogram, semal, "buildmeta");
code::output metacode = code::generate(metaprogram, semal, ret, "buildmeta");
// we now own the codegen handle.
llvm::Module* metaprogram_handle = static_cast<llvm::Module*>(code::unsafe_release());
// pass ownership directly into ExecutionEngine.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/build.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace build

struct info
{
linkage_type link = linkage_type::executable;
linkage_type link = linkage_type::none;
config_type config = config_type::debug;
std::string link_name = "a";
std::vector<std::filesystem::path> extra_input_files = {};
Expand Down
9 changes: 6 additions & 3 deletions cpp/src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace code
void codegen_global_variable(const semal::local_variable_t& globdata, const semal::output& semal_input);
void codegen_nodes(const ast& tree, const semal::output& input);

output generate(const ast& tree, const semal::output& input, std::string module_name)
output generate(const ast& tree, const semal::output& input, const build::info& binfo, std::string module_name)
{
diag::assert_that(program == nullptr && builder == nullptr && debug == nullptr, error_code::ice, "previous codegen state has not been erased and you want me to move onto codegening another file...");
output ret
Expand All @@ -235,7 +235,7 @@ namespace code
};
program = std::make_unique<llvm::Module>(module_name, *ctx);
builder = std::make_unique<llvm::IRBuilder<>>(*ctx);
if(true)
if(binfo.config == build::config_type::debug)
{
debug = std::make_unique<llvm::DIBuilder>(*program);
debug_info.cu = debug->createCompileUnit(llvm::dwarf::DW_LANG_C, debug->createFile(module_name.c_str(), "."), "Psy Compiler", /*optimised*/ false, "", 0);
Expand Down Expand Up @@ -1271,7 +1271,10 @@ namespace code
// automatically add a return :) you're welcome
builder->CreateRetVoid();
}
d.ctx.error(error_code::codegen, "missing return value for function \"{}\"", payload.func_name);
else
{
d.ctx.error(error_code::codegen, "missing return value for function \"{}\"", payload.func_name);
}
}
if(!has_return && funcdata.return_ty.is_void())
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/codegen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace code
void* unsafe_release();
void cleanup();
// perform code generation. `codegen_handle` member of the returned output remains valid until you invoke `code::cleanup()`. ideally, you generate, then dump-ir/write-object, cleanup and then codegen another file.
output generate(const ast& tree, const semal::output& input, std::string module_name = "<unnamed_module>");
output generate(const ast& tree, const semal::output& input, const build::info& binfo, std::string module_name = "<unnamed_module>");

struct state
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/psyc_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int main(int argc, char** argv)
link::state link;
for(const auto& [input_file, semantic_output] : semal.analysed_input_files)
{
codegen.codegend_input_files[input_file] = code::generate(parse.parsed_input_files[input_file], semantic_output, input_file.string());
codegen.codegend_input_files[input_file] = code::generate(parse.parsed_input_files[input_file], semantic_output, binfo, input_file.string());
if(args.should_dump_ir)
{
std::cout << "==========================\n";
Expand Down
113 changes: 6 additions & 107 deletions samples/scratchpad.psy
Original file line number Diff line number Diff line change
@@ -1,120 +1,19 @@
123;
12345;

hio : i64 := 64;

nesteddata :: struct
{
flak : i64;
}

mydata :: struct
{
member : i64 := 5;
member2 : i64 := 69;
nested : nesteddata;
}
//xyz : mydata;
//xyz.member;

get_data :: () -> mydata
{
ret : mydata;
(ret.nested.flak) = 9;
return ret;
}
//class :: typedef := mydata;

putchar :: (ch : i8) -> u0 := extern;
dub :: (val : i64) -> i64
print_digit :: (digit : i64) -> u0
{
vvptr : i64&& const;
deref vvptr = (55@u64& weak);
vv : f64 weak := 5;
vv = 50;

ptr : i64& := __builtin_malloc(123@u64);
longptr : i64& := (ptr);
defer __builtin_free(ptr);

is_cringe : bool := (true == false);
val = deref ref val;
val = val - val;
v : i64&;
val = ((val * val) * (val * deref v));
deref v = 862;
-deref v;
your_mum : i64 := 0;
// return val * 2

myint : i64 := 0;
for myint = 0, myint == 5, myint = myint + 1
{
putchar(myint@i8);
}
return (val * 2);
}

complicated :: (par1 : i64, par : i64, par3 : i64) -> i64
{
putchar(-par@i8);
return 0;
}

poggers : i64 := 5;
morb :: (par0 : i64) -> f64
{
poggers1 : i64;
poggers2 : i64;
poggers3 : i64;
//morb2 :: (par0 : i64) -> u0 := extern;
mydata123 : mydata;
complicated(poggers, dub(5), mydata123.member2);
complicated(--complicated(1, 2, 3), dub(5), 690);

phicond : i64 := 5;
phi1 : i64 := 0;
if phicond == 5
{
phi1 = 56;
return 5.0;
}
putchar(phi1@i8);

if poggers1 == 59
{
e : i64 := 5;
}
else if poggers2 == 12
{
// ur cringe m8.
d : i64 := 5;
if par0 == 5
{

}
else
{
if poggers3 == 0
{

}
}
}

retval : f64;
return retval;
//return morb(5 * complicated(dub(5)));
putchar((48 + digit)@i8);
}

main :: () -> i64
{
putchar(48@i8);
print_digit(1);
print_digit(2);
print_digit(3);
return 0;
}

== default : build ==
{
set_build_type(release);
set_build_type(debug);
set_linkage_type(executable);
}

0 comments on commit 64d3f6c

Please sign in to comment.