diff options
| author | Timon Kruiper <timonkruiper@gmail.com> | 2021-04-08 14:22:56 +0200 |
|---|---|---|
| committer | Timon Kruiper <timonkruiper@gmail.com> | 2021-04-08 14:22:56 +0200 |
| commit | 91e416bbf049b875d090ba050081d9964ed4b452 (patch) | |
| tree | cfb780ee22b3b5da33c574489dca348bb632ae5f /src/Sema.zig | |
| parent | 272fe0cbfe4d59a307389e20b3bf57099b182ebe (diff) | |
| download | zig-91e416bbf049b875d090ba050081d9964ed4b452.tar.gz zig-91e416bbf049b875d090ba050081d9964ed4b452.zip | |
stage2: add a simplified export builtin call
std.builtin.ExportOptions is not yet supported, thus the second argument
of export is now a simple string that specifies the exported symbol
name.
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 519d5df401..d2abaaf091 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -342,6 +342,10 @@ pub fn analyzeBody( try sema.zirValidateStructInitPtr(block, inst); continue; }, + .@"export" => { + try sema.zirExport(block, inst); + continue; + }, // Special case instructions to handle comptime control flow. .repeat_inline => { @@ -1333,6 +1337,31 @@ fn analyzeBlockBody( return &merges.block_inst.base; } +fn zirExport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void { + const tracy = trace(@src()); + defer tracy.end(); + + const inst_data = sema.code.instructions.items(.data)[inst].pl_node; + const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data; + const src = inst_data.src(); + + const target_fn = try sema.resolveInst(extra.lhs); + const target_fn_val = try sema.resolveConstValue( + block, + .{ .node_offset_builtin_call_arg0 = inst_data.src_node }, + target_fn, + ); + + const export_name = try sema.resolveConstString( + block, + .{ .node_offset_builtin_call_arg1 = inst_data.src_node }, + extra.rhs, + ); + + const actual_fn = target_fn_val.castTag(.function).?.data; + try sema.mod.analyzeExport(&block.base, src, export_name, actual_fn.owner_decl); +} + fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void { const tracy = trace(@src()); defer tracy.end(); |
