What is a good and simple middleware?

Suppose the purpose of the assignment is to write a compiler that works with a subset of the C language (you can read a subset of any language by simply maintaining the main expressiveness of the scripts without having complicated things like objects).

What intermediate code can be used to verify the compiler? I talked with the professor, and he talked about the fact that he did not know what to give his students as a virtual machine to be used for the β€œcompiled code”, so I thought that might be a good solution.

Subset of C -> Compiler -> Code? -> VM

in which the code can be either in binary format or better in ASCII format (something like pseudo-asm).

I'm looking for something already done, and not how to structure this intermediate code and virtual machine, just lightweight and simple, ready to test some compiled programs.

+3
source share
5 answers

You can describe some abstract design of the machine, and then provide it with a set of commands in a list format. I am a small parser LISP is an expert in parsers.

(label add-two)
(init-stack-frame 2)
(load r1 0)
(load r2 1)
(add val r1 r2)
(goto cont)

Also, writing a LISP interpreter to read this is an expert.

load_labels (index, expr, env)
    if expr.first == 'label'
        env.set(expr.second, index)

interpret (machine, expr, env)
    return env.lookup(expr.first).eval(machine, expr.tail)
+2
source

There are many examples of intermediate code / bytecode in existing virtual machines . Depending on your definition, they may or may not be simple. Examples:

+1

(, JavaScript)? .

0

Java? , , , , , amazon.com , vm.

80x86 68000, , . , - , , .

LISP: -)

0

What about llvm ?

0
source

Source: https://habr.com/ru/post/1755333/


All Articles