From de6cc94e3b7fa5d1b8eeb53993dbf3ca2cec1cc1 Mon Sep 17 00:00:00 2001 From: cheneym2 Date: Thu, 20 Mar 2025 11:38:46 -0400 Subject: Add -dump-module command to slangc (#6638) * Add -dump-module command to slangc The new -dump-module command to slangc will load and disassemble a slang module, similar to what would be seen by the -dump-ir command, except that -dump-ir tells slangc to print IR as it performs some compilation command. That is, -dump-ir requires some larger compilation task. -dump-module on the otherhand requires no additional goal and will simply load a module and print its IR to stdout independently from other compilation steps. Its intended purpose is to inspect .slang-module files on disk. It can also be used on .slang files which will be parsed and lowered if slang does not find an associated ".slang-module" version of the module on disk. The compilation API is extended with a new IModule::disassemble() method which retrieves the string representation of the dumped IR. Closes #6599 * format code * Use FileStream not FILE * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Ellie Hermaszewska --- tests/ir/dump-module.slang | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/ir/dump-module.slang (limited to 'tests') diff --git a/tests/ir/dump-module.slang b/tests/ir/dump-module.slang new file mode 100644 index 000000000..e22c3fca5 --- /dev/null +++ b/tests/ir/dump-module.slang @@ -0,0 +1,53 @@ +// This tests slangc's -dump-module command. +// Dumping ".slang" should mean just that, and it should not automatically load up +// a ".slang-module" when available, because the intent of the -dump-module command +// is to see the file you requested. If there's a bug in slang-module output, it's +// important that -dump-module looks at the specific file you requested. + +//TEST:COMPILE: tests/ir/dump-module.slang -o tests/ir/dump-module.slang-module -target spirv -embed-downstream-ir + +//TEST:SIMPLE(filecheck=CHECK1): -dump-module tests/ir/dump-module.slang-module +//TEST:SIMPLE(filecheck=CHECK2): -dump-module tests/ir/dump-module.slang + +module "export-library-generics"; + +public cbuffer Constants { + public float x; + public float y; +} + +interface MyInterface +{ + int myMethod(int a); +} + +struct MyType : MyInterface +{ + int myMethod(int a) + { + return a * 3; + } +} + +int genericFunc(T arg) +{ + return arg.myMethod(3); +} + +public int normalFuncUsesGeneric(int a) +{ + MyType obj; + return genericFunc(obj); +} + +public int normalFunc(int a, float b) +{ + return a - floor(b); +} + +// CHECK1:EmbeddedDownstreamIR(6 : Int, +// CHECK1: OpCapability Linkage + +// CHECK2-NOT:EmbeddedDownstreamIR(6 : Int, +// CHECK2-NOT: OpCapability Linkage + -- cgit v1.2.3